Environment
Identity Manager 4.5 - Active directory shim
Situation
Need to execute multiple powershell commands via the active directory shim powershell interface
For Eg: In the below example account needs to be enabled for Lync.
$spwd = ConvertTo-SecureString "sjSD8jsdJAJDs" -AsPlainText -Force;
$mycreds = New-Object System.Management.Automation.PSCredential ("Client/pdsadmin", $spwd);
$sessionOption = New-PSSessionOption -SkipRevocationCheck:$true -SkipCACheck:$true -SkipCNCheck:$true;
$session = New-PSSession -ConnectionURI "https://dcsvr1.Client.ad.local/OcsPowershell" -Credential $mycreds -SessionOption $sessionOption;
Import-PsSession $session -AllowClobber;
enable-csuser -Identity "CN=lynctestu1,CN=Users,DC=Client,DC=ad,DC=local" -Registrar "dcsvr1.Client.ad.local" -SipAddress "sip:lynctestu1@Client.ad.local" -DomainController "dcsvr1.Client.ad.local";
Remove-PSSession $session;
The driver may report the following error :
Error completing powershell command. ERROR:
For Eg: In the below example account needs to be enabled for Lync.
$spwd = ConvertTo-SecureString "sjSD8jsdJAJDs" -AsPlainText -Force;
$mycreds = New-Object System.Management.Automation.PSCredential ("Client/pdsadmin", $spwd);
$sessionOption = New-PSSessionOption -SkipRevocationCheck:$true -SkipCACheck:$true -SkipCNCheck:$true;
$session = New-PSSession -ConnectionURI "https://dcsvr1.Client.ad.local/OcsPowershell" -Credential $mycreds -SessionOption $sessionOption;
Import-PsSession $session -AllowClobber;
enable-csuser -Identity "CN=lynctestu1,CN=Users,DC=Client,DC=ad,DC=local" -Registrar "dcsvr1.Client.ad.local" -SipAddress "sip:lynctestu1@Client.ad.local" -DomainController "dcsvr1.Client.ad.local";
Remove-PSSession $session;
The driver may report the following error :
Error completing powershell command. ERROR:
Resolution
The powershell commands have to be submitted as script block, by enclosing the commands within curly braces and then preceding with an ampersand as shown below
<modify cached-time="20150422124346.854Z" class-name="user" event-id="svr1-NDS#20150422124346#1#1:4d3833ca-7f07-4f4f-b06c-aa7375395d40" qualified-src-dn="O=Data\OU=Users\CN=slamb" src-dn="\IDVT\customer\Data\Users\lynctestu1" src-entry-id="42436" timestamp="1429706626#2">
<association state="associated">865a8e046379b348ab866b0b985e0ed2</association>
<modify-attr attr-name="PSExecute">
<remove-all-values/>
<add-value>
<value type="string">&{$spwd = ConvertTo-SecureString "sjSD8jsdJAJDs" -AsPlainText -Force;$mycreds = New-Object System.Management.Automation.PSCredential ("Client/pdsadmin", $secpasswd);$sessionOption = New-PSSessionOption -SkipRevocationCheck:$true -SkipCACheck:$true -SkipCNCheck:$true;$session = New-PSSession -ConnectionURI "https://dcsvr1.Client.ad.local/OcsPowershell" -Credential $mycreds -SessionOption $sessionOption;Import-PsSession $session -AllowClobber;enable-csuser -Identity "CN=lynctestu1,CN=Users,DC=Client,DC=ad,DC=local" -Registrar "dcsvr1.Client.ad.local" -SipAddress "sip:lynctestu1@Client.ad.local" -DomainController "dcsvr1.Client.ad.local";Remove-PSSession $session;}</value>
</add-value>
</modify-attr>
</modify>
<modify cached-time="20150422124346.854Z" class-name="user" event-id="svr1-NDS#20150422124346#1#1:4d3833ca-7f07-4f4f-b06c-aa7375395d40" qualified-src-dn="O=Data\OU=Users\CN=slamb" src-dn="\IDVT\customer\Data\Users\lynctestu1" src-entry-id="42436" timestamp="1429706626#2">
<association state="associated">865a8e046379b348ab866b0b985e0ed2</association>
<modify-attr attr-name="PSExecute">
<remove-all-values/>
<add-value>
<value type="string">&{$spwd = ConvertTo-SecureString "sjSD8jsdJAJDs" -AsPlainText -Force;$mycreds = New-Object System.Management.Automation.PSCredential ("Client/pdsadmin", $secpasswd);$sessionOption = New-PSSessionOption -SkipRevocationCheck:$true -SkipCACheck:$true -SkipCNCheck:$true;$session = New-PSSession -ConnectionURI "https://dcsvr1.Client.ad.local/OcsPowershell" -Credential $mycreds -SessionOption $sessionOption;Import-PsSession $session -AllowClobber;enable-csuser -Identity "CN=lynctestu1,CN=Users,DC=Client,DC=ad,DC=local" -Registrar "dcsvr1.Client.ad.local" -SipAddress "sip:lynctestu1@Client.ad.local" -DomainController "dcsvr1.Client.ad.local";Remove-PSSession $session;}</value>
</add-value>
</modify-attr>
</modify>
The second option is to not use the ";"
(Please note that the Active Directory driver only supports Active Directory and Exchange PowerShell modules and cmdlets)