Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell GWMI RPC help

Posted on 2015-02-24
2
Medium Priority
?
119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 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