-
Orchestrator spawns processed in 32bit powershell. So if you use any activity that uses 64bit powershell modules. Those modules fail to load.
To overcome this encapsulate your script in the following lines.
C:\Windows\Sysnative\WindowsPowershell\v1.0\Powershell.exe -NonInteractive -Command {
###Enter your script here###
}
2. You can also use the script from the following link. This will need windows remote management to be enabled.And the account being used to be added to Remote Management Users Group.
https://social.technet.microsoft.com/wiki/contents/articles/30721.powershell-system-center-orchestrator-best-practice-template.aspx
$DataBusInput1 = "{Parameter 1 from Initialize Data}"
$DataBusInput2 = "{Global Variable 1}"
$ResultStatus = ""
$ErrorMessage = ""
$Trace = (Get-Date).ToString() + "`t" + "Runbook activity script started" + " `r`n"
$argsArray = @()
$argsArray += $DataBusInput1
$argsArray += $DataBusInput2
$Session = New-PSSession -ComputerName localhost
$ReturnArray = Invoke-Command -Session $Session -Argumentlist $argsArray -ScriptBlock {
Param(
[ValidateNotNullOrEmpty()]
[string]$DataBusInput1,
[ValidateNotNullOrEmpty()]
[string]$DataBusInput2
)
function AppendLog ([string]$Message)
{
$script:CurrentAction = $Message
$script:TraceLog += ((Get-Date).ToString() + "`t" + $Message + " `r`n")
}
$ResultStatus = ""
$ErrorMessage = ""
$script:CurrentAction = ""
$script:TraceLog = ""
try
{
AppendLog "Script now executing in external PowerShell version [$($PSVersionTable.PSVersion.ToString())] session in a [$([IntPtr]::Size * 8)] bit process"
AppendLog "Running as user [$([Environment]::UserDomainName)\$([Environment]::UserName)] on host [$($env:COMPUTERNAME)]"
AppendLog "Parameter values received: DataBusInput1=[$DataBusInput1]; DataBusInput2=[$DataBusInput2]"
AppendLog "Doing first action"
AppendLog "Doing second action"
if($DataBusInput1 -ilike "*bad stuff*")
{
throw "ERROR: Encountered bad stuff in the parameter input"
}
$myCustomVariable = "Something I want to publish back to the runbook data bus"
AppendLog "Finished work, determining result"
$EverythingWorked = $true
if($EverythingWorked -eq $true)
{
$ResultStatus = "Success"
}
else
{
$ResultStatus = "Failed"
}
}
catch
{
$ResultStatus = "Failed"
$ErrorMessage = $error[0].Exception.Message
AppendLog "Exception caught during action [$script:CurrentAction]: $ErrorMessage"
}
finally
{
if($ErrorMessage.Length -gt 0)
{
AppendLog "Exiting external session with result [$ResultStatus] and error message [$ErrorMessage]"
}
else
{
AppendLog "Exiting external session with result [$ResultStatus]"
}
}
$resultArray = @()
$resultArray += $ResultStatus
$resultArray += $ErrorMessage
$resultArray += $script:TraceLog
$resultArray += $myCustomVariable
return $resultArray
}
$ResultStatus = $ReturnArray[0]
$ErrorMessage = $ReturnArray[1]
$Trace += $ReturnArray[2]
$MyCustomVariable = $ReturnArray[3]
$Trace += (Get-Date).ToString() + "`t" + "Script finished" + " `r`n"
Remove-PSSession $Session