How to execute a powershell script which will make SSH connection using a windows mid server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have a requirement to execute a powershell script which will execute on a MID server hosted on a windows server that in turn makes a powershell ssh connection.
The script I am trying to execute is given below and it is passed as a variable to the Powershell step,
#****** Format to access Input Parameters *******
# To use variable, prefix with '$'. eg. $message
# Read more https://docs.servicenow.com/?context=CSHelp:IntegrationHub-PowerShell-Step
#****** Reserved variables available when remoting type is Run on MID
# $computer Host IP resolved from Connection alias
# $cred Credential Object. Credential resolved via connection alias or credential alias. This can be used in conjunction with any cmd-let which support credential parameter eg. New-PSSession -credential $cred
# $log_info mid property "mid.property.powershell.log_info" set on instance to enable debugging. So it's a flag available to act on and add any verbose logging if they want to in their script
$ErrorActionPreference = "Stop"
try{
$Session = New-PSSession -ComputerName $Servername -Credential $cred
$Result = Invoke-Command -Session $Session -ScriptBlock {
iex $Using:pscript
}
Write-Host $Result
}
catch{
[PSCustomObject]@{
result = $_.exception.message
} | ConvertTo-Json
}
- Labels:
-
Event Management
-
Orchestration (ITOM)
