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
if I just do
Get-WMIObject -query "select * from win32_logicaldisk where DriveType = '3'" -computer server
that works
Thanks for your reply
Unfortunately it's giving me that message for all 250 server
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 }
You're right
it returns
System.Data.DataRow
Any Idea?
thanks lots
Type this in for debugging purposes:
$arrservers = Get-SqlData 'Server\Instance' InstanceName "SELECT Name FROM tbl_Server_BI_AD" $arrservers[0] | get-member
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;}
'Name' property looks promising. Try:
$arrservers = Get-SqlData 'Server\Instance' InstanceName "SELECT Name FROM tbl_Server_BI_AD" $arrservers[0] | select name
Yes, I'm getting the server name!!!
How to I employ that now in my script? Would you help me out there?
Thanks lots
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 }
That's it.
Im marking it as solved.
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