Solved

Powershell GWMI RPC help

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

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
Thank you oBdA

Works as you said :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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 …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now