Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Testing if PS remoting is enabled, background job blocked because of credentials prompt

$
0
0

Hi,

 

I have a rather complex PS inventory script that scans all specified network subnets, pings IPs, tries to pull WMI data from those IPs using any number of saved credentials combos, and if it finds something that works then runs a bunch of WMI queries and similar checks, then compiles all that into an Excel spreadsheet. Considering we scan local and remote sites over WAN links, have about 7500+ devices on about 40K scanned IPs and script taking about 5 minutes to complete, I'm using Start-Job for each pingable IP to run the data gathering as background jobs (200-400 of them depending on where I run, memory constraints on local box). The inventory takes about 12-14 hours, which is all fine as we run it overnight.

 

Now - I've had an item in the script that checks whether PowerShell remoting is enabled on the target computer. For this I used simple and effective method :

If (Invoke-Command -Credential $Credentials -ComputerName $Hostname { 1 } ){"YES"}else{"NO"}

 

Then about a week ago we enabled PS remoting across the enterprise, on all 2008+ servers. The idea with inventory script is to confirm this was in fact applied and to identify any computers where it was't and fix those.

The problem I'm having now is that on some computers (haven't found a pattern yet), the background jobs will never complete and will go into "Blocked" state. When I do Get-Job | Receive Job, I get a prompt on the screen asking for credentials. This leads me to believe that whatever credentials I'm trying to use for this particular target are not good enough and target wants something else.

I need a way to test whether PS remoting is enabled, without getting a prompt for credentials (or somehow handling that to get rid of the prompt). Bear in mind the credentials supplied are good enough to pull WMI data out so this is not just ordinary user account, it should have admin privileges on the target. I tried using Try / Catch but the Invoke-Command command doesn't fail, it just gets stuck on prompt screen awaiting input.

 

 

Thanks


Viewing all articles
Browse latest Browse all 6937

Trending Articles