As of Identity Panel version 6, the panel platform uses Windows PowerShell Core 7 for schedule steps and workflows.
Sometimes it may be necessary to run scripts that use modules which are only supported in Windows PowerShell 5.
The following script shows how to shell to an underlying Windows PowerShell session to leverage the Microsoft Active Directory PowerShell module:
Import-Module ActiveDirectory -UseWindowsPowerShell 3> $null $s = Get-PSSession -Name WinPSCompatSession Invoke-Command -Session $s -ScriptBlock { param($example...) # script to run here } -ArgumentList $example...
Another example of this approach is an alternative to using the native MIM Provider to update Person data in the MIM Service via the LithnetRMA PowerShell module. In this example the script sets the $JobTitle attribute for the supplied $AccountName on a target $MIMServer. Note that for this to run the the LithnetRMA module must first be deployed on the targeted Panel Service host:
param([string]$AccountName, [string]$MIMServer, [string]$JobTitle)
Import-Module LithnetRMA -WarningAction SilentlyContinue > $null
$s = Get-PSSession -Name WinPSCompatSession -WarningAction SilentlyContinue
Invoke-Command -Session $s -ScriptBlock {
param([string]$AccountName, [string]$MIMServer, [string]$JobTitle)
Set-ResourceManagementClient -BaseAddress ("http://{0}:5725" -f $MIMServer);
$obj = Get-Resource -ObjectType Person -AttributeName AccountName -AttributeValue $AccountName -AttributesToGet @("AccountName","JobTitle");
if ($obj) {
$obj.JobTitle = $JobTitle;
Save-Resource $obj
}
} -ArgumentList $AccountName, $MIMServer, $JobTitle
For details on now to set up your Panel Service and MIM Server to support this pattern refer to the KB article Q&A: Configure Identity Panel to access the MIM Service using PowerShell.
Comments
1 comment
I find it best to enclose the nearly the whole script in a try/catch as an exception throw will crash the service. The given Get-PSSession doesn't work in my environment but just using invoke-command with computername localhost does work to get the session in a workable environment for the lithnet module.
Please sign in to leave a comment.