Sunday, January 29, 2017

Use DS Commands with Powershell

In this blog post I will share a TIP on how to use DS utilities inside your scripts.

There are situations when you have limitation of using AD modules or you can't use third-party Shells like Quest AD Shell.


DS utilities are very handy & can do most of the things related to active directory.

Sharing few examples from real script:

In the below sample code,I have updated the description of he user by using DSMOD, Important to note here is operator 2>&1 at the

end, that is used to capture the success/error.


$dm = $null
$dm = dsmod user $dn -desc $description 2>&1
if ($dm -like "*dsmod succeeded*")
Write-Host "Updating Description for $SharedMailboxAlias" -ForegroundColor Green
$mcoll.Description = "Updated"


you can use 2>&1 (Redirection)with other command line utilities as well. As per definition it

Sends errors (2) and success output (1) to the success output stream.

Below example uses another DS utility DSADD to create a group & captures the Success /failure as described above.

-----------Another Example from one of my live script--------

$dm = $null
$dm = dsadd group $fgpname 2>&1
if ($dm -like "*dsadd succeeded*")
Write-Host "Group $fgpname Created" -ForegroundColor Green



Sharing the last example to ADD a memeber to the group

$dm = dsmod group $fgpname -addmbr $userdn 2>&1

You can now easily correlate the usage of ds utilities with powershell & can work thru your scripts in various situations

where AD module/ third party modules are not available, you can also use ADSI scripting but here

I am just sharing one other aspect that can be utilized.


Thanks for Reading

Sukhija Vikas


No comments:

Post a Comment