Solved

Powershell GWMI RPC help

Posted on 2015-02-24
2
84 Views
Last Modified: 2015-02-24
Hi

We use the following code below supplied by Qlemo to search a list of PC's to see who is logged on using RPC and then output to a .csv

#Create Blade Output
gwmi -computer (gc c:\blades\blades.txt) Win32_ComputerSystem |
  select @{n='Blade'; e={$_.Name}},
             @{n='User'; e={ if ($_.UserName) { $_.Username } else { "No user" }} } |
             
 Export-CSV c:\blades\output.csv

Open in new window


Evening works great until a PC in the list is switched off

When using the code via Task Scheduler we see that the output file is not being created when a PC has been switched off by a User.

Is there away to deal with the below issue by adding the "PC name" and "Switched off" to the output file but also clearing the message so that it continues to check all other PC's in the list.


gwmi : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\xampp\htdocs\blades\DE_Blades.ps1:71 char:1
+ gwmi -computer (gc c:\xampp\htdocs\blades\dk\dk_blades_list.txt) Win32_ComputerS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Thank you in advance

Si
0
Comment
Question by:Si Walton
2 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 40627934
Get-Content C:\blades\blades.txt | % {
	$Blade = $_
	Try {
		Get-WmiObject -Computer $Blade Win32_ComputerSystem -ErrorAction Stop | Select-Object -Property `
			@{n='Blade'; e={$Blade}},
			@{n='User'; e={If ($_.UserName) {$_.Username} Else {"No user"}}},
			@{n='Exception'; e={}}
	} Catch {
		$_.Exception | Select-Object -Property `
			@{n='Blade'; e={$Blade}},
			@{n='User'; e={"n/a"}},
			@{n='Exception'; e={$_.Message}}
	}
} | Export-CSV c:\blades\output.csv

Open in new window

0
 
LVL 1

Author Closing Comment

by:Si Walton
ID: 40627957
Thank you oBdA

Works as you said :)
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
A procedure for exporting installed hotfix details of remote computers using powershell
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question