Using Quest Active roles powershell snappin QAD Snappin download in type in the command
get-qadcomputer -osname ‘windows*server*’ | format-table -hidetableheader -property dnshostname > outputfilepath
This will retrieve the DNS name of the servers.
Open excel (or other spreadsheet app) and open the text file outputfilepath as a text delimited file and set the delimiter to the full stop or period character “.” this should separate the hostname in to a seperate column and you now delete the cells that contain the remainder of the DNS name of the servers.
Save the file as a text file and rename to something like srvhosts.txt or you can over write the original file…as long as you remember the cleaned up file path and name we are ok
Now we need to get the contents of the file in to an array….
we do this by typing
we do this by typing
$slist = (get-content outputfilepath)
test the contents by typing
$slist
you should see a list of hostnames fly up the screen, remember the array is still active as long as you have kept the same session in powershell, now we can iterate through the array like so
foreach ($srv in $slist) {get-wmiobject -class win32_bios -computer $srv | format-list -property manufacturer,serialnumber,path >> outputfilepath}
Basically this command goes through the file containing the hostnames line by line, reads in the hostname and connects via WMI and reports the manufacturer, serialnumber (aka tag) and Path (which also displays the hostname) and redirects this to a text file that can be searched.
NOTE you need the double chevrons >> or the "append" text redirector so the text output file is not overwritten on each revolution of the foreach loop…I’ve already made that mistake.
The above command will not fit on a whole line so powershell wraps in to the next line.
A nice by product is that Virtualised servers dont have tags, instead the Hosting server dishes out a VMWare tag and that lets you know the servers is virtualised…superb!!!
Limitations…permissions to access remote servers from the credentials currently being used.
AD has a hostname character length limitation, some servers exceed the name length and therefore are incorrectly reported to AD.
Requirements…powershell V2.0, QAD Active roles snapin,and excel
Another way of using the text file is without a defined FOREACH loop, Powershell can imply foreach loops…here is an example…
get-wmiobject -class win32_bios -computer (get-content somecleanflattextfilepath) | format-table -property manufacturer,serialnumber,path
This time the server list contained in the (get-content somecleanflattextfilepath) is automatically iterated through and passed to the commands….which is cool!!!!!!!!! the output can be redirected to a text file too.
I should also mention that since you are querying the WMI class win32_bios if the server has been virtualised in VMWare, then VMWare will generate a virtualised bios result...usualy it starts with vmware......and numbers or text strings, I'll look out an example...anyway from that the point really is you can tell what is physical and what is virtual...
No comments:
Post a Comment