Collect Drive Information with Get-WMIObject
 
 
I'm trying to collect information using this script

$arrservers = Get-SqlData 'Server\Instance' InstanceName "SELECT Name FROM tbl_Server_BI_AD"
foreach ($server in $arrservers){
Get-WMIObject -query "select * from win32_logicaldisk where DriveType = '3'" -computer $server
}

But it fails with this error

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\Users\WeissK022D\Desktop\Get-DriveInfo.ps1:8 char:14
+ Get-WMIObject <<<<  -query "select * from win32_logicaldisk where DriveType = '3'" -computername $server
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Any help is highly appreciated

Note: Get-SqlData is a cmdlet from SQLPSX.codeplex.com
 
 
November 2nd, 2011 4:03pm

perhaps a firewall is on?   it isnt able to use the RPC service to pull the data. I've seen some sites that disable remote RPC, but its probably a firewall issue.    
Free Windows Admin Tool Kit Click here and download it now
November 2nd, 2011 4:07pm

if I just do

 

Get-WMIObject -query "select * from win32_logicaldisk where DriveType = '3'" -computer server

 

that works

November 2nd, 2011 4:09pm

well based on the code, you are hitting several servers.   try spitting out the server names with it to figure out which server is giving the issue.   $arrservers = Get-SqlData 'Server\Instance' InstanceName "SELECT Name FROM tbl_Server_BI_AD" foreach ($server in $arrservers){ write-host "Server: $server" Get-WMIObject -query "select * from win32_logicaldisk where DriveType = '3'" -computer $server }   that way, it should display the server name that is presenting the problem. maybe its not correct in the DB?    
Free Windows Admin Tool Kit Click here and download it now
November 2nd, 2011 4:12pm

Thanks for your reply

Unfortunately it's giving me that message for all 250 server

November 2nd, 2011 4:14pm

Your variable $server obviously does not contain a resolvable host name.  Debug it like this:

$arrservers = Get-SqlData 'Server\Instance' InstanceName "SELECT Name FROM tbl_Server_BI_AD"
 foreach ($server in $arrservers){
 #Get-WMIObject -query "select * from win32_logicaldisk where DriveType = '3'" -computer $server
Write-host $server -fore green
 }
 

 

Free Windows Admin Tool Kit Click here and download it now
November 2nd, 2011 4:14pm

You're right

it returns

System.Data.DataRow

Any Idea?

thanks lots

 

November 2nd, 2011 4:19pm

Type this in for debugging purposes:

$arrservers = Get-SqlData 'Server\Instance' InstanceName "SELECT Name FROM tbl_Server_BI_AD"
$arrservers[0] | get-member

Free Windows Admin Tool Kit Click here and download it now
November 2nd, 2011 4:24pm

   TypeName: System.Data.DataRow

 

Name              MemberType            Definition

----              ----------            ----------

AcceptChanges     Method                System.Void AcceptChanges()

BeginEdit         Method                System.Void BeginEdit()

CancelEdit        Method                System.Void CancelEdit()

ClearErrors       Method                System.Void ClearErrors()

Delete            Method                System.Void Delete()

EndEdit           Method                System.Void EndEdit()

Equals            Method                bool Equals(System.Object obj)

GetChildRows      Method                System.Data.DataRow[] GetChildRows(string relationName), System.Data.DataRow[] GetChildRows(string relatio...

GetColumnError    Method                string GetColumnError(int columnIndex), string GetColumnError(string columnName), string GetColumnError(Sy...

GetColumnsInError Method                System.Data.DataColumn[] GetColumnsInError()

GetHashCode       Method                int GetHashCode()

GetParentRow      Method                System.Data.DataRow GetParentRow(string relationName), System.Data.DataRow GetParentRow(string relationNam...

GetParentRows     Method                System.Data.DataRow[] GetParentRows(string relationName), System.Data.DataRow[] GetParentRows(string relat...

GetType           Method                type GetType()

HasVersion        Method                bool HasVersion(System.Data.DataRowVersion version)

IsNull            Method                bool IsNull(int columnIndex), bool IsNull(string columnName), bool IsNull(System.Data.DataColumn column), ...

RejectChanges     Method                System.Void RejectChanges()

SetAdded          Method                System.Void SetAdded()

SetColumnError    Method                System.Void SetColumnError(int columnIndex, string error), System.Void SetColumnError(string columnName, s...

SetModified       Method                System.Void SetModified()

SetParentRow      Method                System.Void SetParentRow(System.Data.DataRow parentRow), System.Void SetParentRow(System.Data.DataRow pare...

ToString          Method                string ToString()

Item              ParameterizedProperty System.Object Item(int columnIndex) {get;set;}, System.Object Item(string columnName) {get;set;}, System.O...

Name              Property              System.String Name {get;set;}

 

November 2nd, 2011 4:31pm

'Name' property looks promising.  Try:

$arrservers = Get-SqlData 'Server\Instance' InstanceName "SELECT Name FROM tbl_Server_BI_AD"
$arrservers[0] | select name

 

Free Windows Admin Tool Kit Click here and download it now
November 2nd, 2011 4:45pm

Yes, I'm getting the server name!!!

 

How to I employ that now in my script? Would you help me out there?

 

Thanks lots

November 2nd, 2011 4:47pm

Yes, I'm getting the server name!!!

 

How to I employ that now in my script? Would you help me out there?

 

Thanks lots


$arrservers = Get-SqlData 'Server\Instance' InstanceName "SELECT Name FROM tbl_Server_BI_AD"
 foreach ($server in $arrservers){
 Get-WMIObject -query "select * from win32_logicaldisk where DriveType = '3'" -computer $server.name
 }
 
Free Windows Admin Tool Kit Click here and download it now
November 2nd, 2011 4:49pm

That's it.

Im marking it as solved.

November 2nd, 2011 4:51pm

Glad to help.  Once you see how to debug, and drill down to the property/object that you want, it's easy.  That's how we do Powershell!
Free Windows Admin Tool Kit Click here and download it now
November 2nd, 2011 4:56pm

Can you help me?

 I tried to do it with Powershell - but I didn't have a luck.... I wrote such code ( after using Google) :
$comps = Get-Content "g:\INSTALL\PowerShell\Scripts\PCs.txt"
foreach ($comp in $comps)
{
#$vOffs = Get-WmiObject -ComputerName $comp.name -Query "SELECT * FROM Win32_Product WHERE Name LIKE 'Microsoft Office%'" |`
 fl PSComputerName, name
 Write-host $comp -fore green
 }
#$vOffs

but script returned error for me:
Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum
ent is null or empty. Supply an argument that is not null or empty and then try
 the command again.
At line:4 char:37
+ $vOffs = Get-WmiObject -ComputerName <<<<  $comp.name -Query "SELECT * FROM W
in32_Product WHERE Name LIKE 'Microsoft Office%'" |`
    + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindi
   ngValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
   Shell.Commands.GetWmiObjectCommand

Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum
ent is null or empty. Supply an argument that is not null or empty and then try
 the command again.
At line:4 char:37
+ $vOffs = Get-WmiObject -ComputerName <<<<  $comp.name -Query "SELECT * FROM W
in32_Product WHERE Name LIKE 'Microsoft Office%'" |`
    + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindi
   ngValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
   Shell.Commands.GetWmiObjectCommand
please help me.

Thanx in advance

 
March 20th, 2015 9:02pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics