- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 04:59 AM
Hi All,
I am facing the problem here with my powershell probe, whenever i try and run my powershell probe against a remote server to
discover the process, the powershell script executes on my host machine that is where the mid server is installed and not on the remote
machine
Ex. I am testing the probe with ip x.x.x.x with midserver MIDSERVER1, then the powershell runs on the host machine where the midserver is
installed and not on the remote machine x.x.x.x
Kindly let me know if i am missing anything.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 03:13 AM
Hi all,
I was able to achieve this by opening a remote session from the mid server to the target machine, below is the code that i used to connect
$fqdn= Resolve-DnsName $computer | Select NameHost -expandproperty NameHost
$s = New-PSSession -ComputerName $fqdn -Credential $cred
$cmd={<-----Powershell script used to get the details of applications from the Target machine------>}
Invoke-Command -Session $s -ScriptBlock $cmd
Remove-PSSession $s

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2017 07:08 AM
Hi Dinesh,
I am not sure still you have this question. As for I know all PowerShell commands will run from MID server only. You can look at the OOB PowerShell probes, all the commands are executed to remote servers through MID Server only. So if you are writing a custom probe then you need to take remote of that machine from Powershell or you need to write commands to execute it from MID Server. You need to use $computer variable for your remote machine $cred variable for the credential. While discovering ServiceNow automatically assign the remote machine hostname into $computer variable and Credential into $cred variable. You don't need to hardcode your credential or hostname in your custom probe.
Suppose if you want to see the running process of your remote machine then your powershell command should be like
Get-process -computername $computer -credential $cred
Let me know if its work for you.
Regards,
Vivek
Based on the impact hit like, helpful or correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2017 09:21 AM
Hi Vivek,
Thanks for the response, but could you confirm if $computer returns the computer hostname, cause when i try, the response is the i.p address
Regards,
Dinesh N

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2017 01:15 AM
Yep!! Checked just now...It takes IP address only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2017 09:06 AM
Hi Dinesh,
Please ensure your host server's wmi port is working.
Get-process -computername $computer -credential $cred
The above command gets executed on MID server and MID inturn gets connected to your host through wmi protocol. So, you need to ensure that.
You can try login to your mid server and open a powershell command prompt to execute below command. You can ignore the $cred for now and manually key in user id and pwd if powershell command prompt asks.
Get-process -computername $computer
Rajesh