Site icon WinCert

Powershell script to get server specifications

<p>Here is the usefull script that will get you server specifications like Server FQDN&comma; Physical or Virtual info&comma; Model&comma; Total Memory&comma; Bios Version&comma; IP and MAC addresses&comma; Subnet mask&comma; Default Gateway&comma; DHCP status&comma; OS type&comma; Service Pack&comma; Serial Number etc&period;<&sol;p>&NewLine;<p>Create a servers&period;txt file with the list of servers for which you want to get the server specifications&period; One server per line&period;<&sol;p>&NewLine;<p><strong>C&colon;&bsol;temp&bsol;serverslist&period;txt<&sol;strong><&sol;p>&NewLine;<p><strong>serverslist&period;txt<&sol;strong> example&colon;<&sol;p>&NewLine;<p><em>hostname<&sol;em><br &sol;>&NewLine;<em>hostname2<&sol;em><br &sol;>&NewLine;<em>hostname3<&sol;em><&sol;p>&NewLine;<p>Now create a new text file and rename it to <strong>serverlist&period;ps1<&sol;strong><&sol;p>&NewLine;<pre>&dollar;Excel &equals; New-Object -Com Excel&period;Application &NewLine;&dollar;Excel&period;visible &equals; &dollar;True &NewLine;&dollar;Excel &equals; &dollar;Excel&period;Workbooks&period;Add&lpar;&rpar; &NewLine;&num; Insert text in to first row&period; &NewLine;&dollar;Sheet &equals; &dollar;Excel&period;WorkSheets&period;Item&lpar;1&rpar; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;1&rpar; &equals; "Server" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;2&rpar; &equals; "FQDNName" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;3&rpar; &equals; "Manufacturer" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;4&rpar; &equals; "Model" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;5&rpar; &equals; "TotalPhysicalMemory" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;6&rpar; &equals; "isVirtual" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;7&rpar; &equals; "SerialNumber" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;8&rpar; &equals; "Bios Version" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;9&rpar; &equals; "IP Address" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;10&rpar; &equals; "MAC Address" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;11&rpar; &equals; "IPSubnet" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;12&rpar; &equals; "DefaultGateway" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;13&rpar; &equals; "Type" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;13&rpar; &equals; "DHCPEnabled" &NewLine;&dollar;Sheet&period;Cells&period;item&lpar;1&comma;17&rpar; &equals; "OperatingSystem" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;18&rpar; &equals; "ServicePack" &NewLine;&dollar;Sheet&period;Cells&period;item&lpar;1&comma;19&rpar; &equals; "BuildNumber" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;20&rpar; &equals; "BuildType" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;21&rpar; &equals; "Version" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;1&comma;22&rpar; &equals; "SerialNumberOS" &NewLine;&num; Format colors&period; &NewLine;&dollar;WorkBook &equals; &dollar;Sheet&period;UsedRange &NewLine;&dollar;WorkBook&period;Interior&period;ColorIndex &equals; 15 &NewLine;&dollar;WorkBook&period;Font&period;Bold &equals; &dollar;True &NewLine;&num; Go to the second row&period; &NewLine;&dollar;intRow &equals; 2 &NewLine;&num; Select text file which contains list of servers to query&period; &NewLine;&dollar;arrComputers &equals; GC C&colon;&bsol;temp&bsol;serverslist&period;txt &NewLine;&num; Get currently logged in username&comma; client name&comma; manufacturer and model from Win32&lowbar;ComputerSystem class&period; &NewLine;foreach &lpar;&dollar;strComputer in &dollar;arrComputers&rpar;&lbrace; &NewLine;try &lbrace; &dollar;colItems &equals; Get-WmiObject Win32&lowbar;ComputerSystem -Namespace "root&bsol;CIMV2" -ErrorAction stop -ComputerName &dollar;strComputer &NewLine;foreach&lpar;&dollar;objItem in &dollar;colItems&rpar; &lbrace; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;1&rpar; &equals; &dollar;objItem&period;Name &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;2&rpar; &equals; &lpar;&dollar;objItem &vert; &percnt; &lbrace;&dollar;&lowbar;&period;DNSHOSTName &plus;'&period;'&plus;&dollar;&lowbar;&period;domain&rcub;&rpar;&period;ToLower&lpar;&rpar; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;3&rpar; &equals; &dollar;objItem&period;Manufacturer &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;4&rpar; &equals; &dollar;objItem&period;Model &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;5&rpar; &equals; &lpar;&dollar;objItem&period;TotalPhysicalMemory&sol;1024MB&rpar; &NewLine;if&lpar;&dollar;objItem&period;Model -like "VMWare&ast;"&rpar; &NewLine;&lbrace; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;6&rpar; &equals; "Yes" &NewLine;&rcub; &NewLine;Else &NewLine;&lbrace; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;6&rpar;&equals;"No" &NewLine;&rcub; &NewLine;&rcub; &NewLine;&num; Get workstation serial number from Win32&lowbar;BIOS class&period; &NewLine;&dollar;colItems &equals; Get-WmiObject Win32&lowbar;BIOS -Namespace "root&bsol;CIMV2" -ErrorAction stop -ComputerName &dollar;strComputer &NewLine;foreach&lpar;&dollar;objItem in &dollar;colItems&rpar; &lbrace; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;7&rpar; &equals; &dollar;objItem&period;SerialNumber &NewLine;if&lpar;&dollar;objItem&period;BiosVersion -eq &dollar;null&rpar; &NewLine;&lbrace; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;8&rpar;&equals; "Unknown" &NewLine;&rcub; &NewLine;Else &NewLine;&lbrace; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;8&rpar; &equals; &dollar;objItem&period;BiosVersion&lbrack;0&rsqb; &NewLine;&rcub; &NewLine;&rcub; &NewLine;&num;Get OperatingSystme Imforamtion from Win32&lowbar;OperatingSystem &NewLine;&dollar;colItems &equals; Get-WmiObject Win32&lowbar;OperatingSystem -Namespace "root&bsol;CIMV2" -ErrorAction stop -ComputerName &dollar;strComputer &NewLine;foreach&lpar;&dollar;objItem in &dollar;colItems&rpar; &lbrace; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;17&rpar; &equals; &dollar;objItem&period;Name &vert; &percnt; &lbrace; &dollar;&lowbar;&period;Split&lpar;"&vert;"&rpar;&lbrack;0&rsqb; &rcub; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;18&rpar; &equals; &dollar;objItem&period;servicepackmajorversion &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;19&rpar; &equals; &dollar;objItem&period;BuildNumber &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;20&rpar; &equals; &dollar;objItem&period;BuildType &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;21&rpar; &equals; &dollar;objItem&period;Version &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;22&rpar; &equals; &dollar;objItem&period;SerialNumber &NewLine;&rcub; &NewLine;&num; Get IP address and MAC address of the enabled network adapter from Win32&lowbar;NetworkAdapaterConfiguration class&period; &NewLine;&dollar;colItems &equals; Get-WmiObject Win32&lowbar;NetworkAdapterConfiguration -Namespace "root&bsol;CIMV2" -ErrorAction stop -ComputerName &dollar;strComputer &vert; where&lbrace;&dollar;&lowbar;&period;IPEnabled -eq &OpenCurlyDoubleQuote;&dollar;true”&rcub; &NewLine;foreach&lpar;&dollar;objItem in &dollar;colItems&rpar; &lbrace; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;9&rpar; &equals; &dollar;objItem&period;IPAddress&lbrack;0&rsqb; &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;10&rpar; &equals; &dollar;objItem&period;MACAddress &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;11&rpar; &equals; &dollar;objItem&period;IPSubnet &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;12&rpar; &equals; &dollar;objItem&period;DefaultIPGateway &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;13&rpar; &equals; "IPv4" &NewLine;&dollar;Sheet&period;Cells&period;Item&lpar;&dollar;intRow&comma;14&rpar; &equals; &dollar;objItem&period;DHCPEnabled &NewLine;&dollar;intRow&plus;&equals;1 &NewLine;&rcub; &NewLine;&rcub; &NewLine;catch &lbrace; &NewLine;Write-Host "Could not contact &dollar;&lpar;&dollar;strComputer&rpar;" -ForegroundColor Red &NewLine;Out-File -FilePath C&colon;&bsol;Noreach&period;txt -InputObject &dollar;strComputer -Append -Force &NewLine;&rcub; &NewLine;&rcub; &NewLine;<&sol;pre>&NewLine;<p>Save the script to the same folder at <strong>C&colon;&bsol;temp<&sol;strong>&period;<&sol;p>&NewLine;<p>Before you&&num;8217&semi;ll be able to run the script you will have to enable execution policy on your system &lpar;if you haven&&num;8217&semi;t already&rpar;&colon;<&sol;p>&NewLine;<p>Start the Powershell in elevated mode &lpar;Run as Administrator&rpar; and run the following command&colon;<&sol;p>&NewLine;<p><strong>Set-ExecutionPolicy RemoteSigned<&sol;strong><&sol;p>&NewLine;<p>Now run the Powershell script by using this command&colon;<&sol;p>&NewLine;<p><strong>powershell -noexit &&num;8220&semi;&amp&semi; &&num;8220&semi;&&num;8221&semi;C&colon;&bsol;temp&bsol;serverlist&period;ps1&&num;8243&semi;&&num;8221&semi;&&num;8221&semi;<&sol;strong><&sol;p>&NewLine;<p><a href&equals;"https&colon;&sol;&sol;www&period;wincert&period;net&sol;wp-content&sol;uploads&sol;2016&sol;01&sol;server-specifications-1&period;png" rel&equals;"attachment wp-att-1644"><img class&equals;"alignnone size-full wp-image-1644" src&equals;"https&colon;&sol;&sol;www&period;wincert&period;net&sol;wp-content&sol;uploads&sol;2016&sol;01&sol;server-specifications-1&period;png" alt&equals;"server specifications" width&equals;"603" height&equals;"59" &sol;><&sol;a><&sol;p>&NewLine;<p>You should get server specifications results on your screen&period;<&sol;p>&NewLine;

Exit mobile version