Solved

Powershell GWMI RPC help

Posted on 2015-02-24
2
106 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 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

627 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