Hi guys,
I'm a newbie to powershell so forgive my newbie question. I am writing a powershell script to inventory all the servers on our network write that to excel and then use WMI to log into each one and retrieve memory, cpu and other info.
I tried two ways of doing the query and was wondering which one is more efficient to access multiple domains. Of course I'm open to other suggestions as wll.
Even though this way works really well it is taking a bit of time to query and retrieve the server list and so you have you have a blank screen for few minutes while it is thinking. $ADServer=Get-ADComputer-filter {OperatingSystem-like"Windows *server*"} -Properties * -Server$ServerDomain |select Name,description,operatingSystem,operatingsystemservicepack,ipv4address Or I pulled this method of technet and modified it to read multiple fields but I'm having trouble writing the description, os, and extra fields in seperate cells in excel. When I run this method though the server list is retrieved much quicker than the above method. $strCategory="computer" $strOS = "Windows*Server*" $objDomain =New-Object System.DirectoryServices.DirectoryEntry "ldap://", $objSearcher =New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot =$objDomain $objSearcher.Filter = ("(&(objectCategory=$strCategory)(OperatingSystem=$strOS))") $colProplist = "name" , “description”, “operatingSystem”, “OperatingSystemservicepack”,”ipv4address” Foreach {($iin$colPropList){$objSearcher.PropertiesToLoad.Add($i)} $colResults =$objSearcher.FindAll() foreach ($objResultin$colResults) { $objComputer=$objResult.Properties; $objComputer.name $objComputer.operatingSystem $objComputer.operatingsystemservicepack $objcomputer.ipv4address} Thank you in advance