|
|
Question : In Powershell, need to find way to grab all computer names from a given AD OU
|
|
I'm trying to do this efficiently, as I've already accomplished this in a not-so-elegant way. Using the command "Get-QADComputer" from Quest AD Snapin and specifying the scope then doing a pipe and "select-object -property name", I end up with a nice little array full of computer names and related properties from AD. When I attempt to use the name as a Get-WMIObject -computer , it's not working so well.
It comes out like @{Name=} and I have to do an old-fashioned text parse to get it to work. I don't think this is necessary in Powershell. In VBScript it would be though.
Currently, I've tried various ways to do this. I have a subroutine set up for a command like getdrive $computer, but that's after I've parsed the names from their old form of @{Name=}. I'm trying to find a one liner:
Get-QADComputer -scope | ?{getdrive $_}
My Function for the GetDrive is something along the lines of
Function Getdrive{ $ColDisks = Get-WMIObject W32Logicaldisk -computername $args
}
So, I can't do a one liner for the Get-WMIObject because I have quite a bit of code needing to processed in my function... or can I?
Any help?
|
Answer : In Powershell, need to find way to grab all computer names from a given AD OU
|
|
Get-WMIObject takes an Array of Strings for ComputerName so you could just do this
$servers = Get-QADComputer | select dnsName Get-WMIObject Win32_Logicaldisk -computername $servers
or
Get-QADComputer | ?{getdrive $_.dnsHostName}
Note: Your using where-object which expects getdrive to return $true or $false.
|
|
|
|
|