{"id":263,"date":"2017-05-19T10:01:25","date_gmt":"2017-05-19T15:01:25","guid":{"rendered":"http:\/\/www.sqlkitten.com\/?p=263"},"modified":"2017-05-19T10:08:23","modified_gmt":"2017-05-19T15:08:23","slug":"blogging-reboot-and-powershell-get-system-information","status":"publish","type":"post","link":"http:\/\/www.sqlkitten.com\/?p=263","title":{"rendered":"Blogging reboot and PowerShell &#8211; Get System Information"},"content":{"rendered":"<p>After whining about not blogging enough, I am going to do something about this. Whether it is PowerShell or SQL, simple or complex, I know that others can benefit from my knowledge and expand their skill sets.<\/p>\n<p>And you are like &#8220;That&#8217;s great Amy&#8230;where&#8217;s the PowerShell we are here for?&#8221; Ok, Ok&#8230;.keep your drawers on! \ud83d\ude09<\/p>\n<p>Recently I was tasked with gathering the system information from all of the servers at a client. Another opportunity for some PowerShell dominance.<\/p>\n<pre class=\"lang:ps decode:true\" title=\"get_sysinfo.ps1\">&lt;#\r\nName: get_sysinfo.ps1\r\nAuthor: Amy Herold\r\nDate: 03 May 2017\r\nPurpose: Get the system information from a list of computers\/servers, doing one machine at a time and outputting server name\r\nwhen you can&#039;t connect. Output information to a NFO file with the name of the machine.\r\n\r\nNotes: Get your list of servers and update the $servers variable below. Make sure they are also formatted the same way as in the sample.\r\nUpdate the $path variable with where you want to save the NFO files.\r\n#&gt;\r\n\r\n\r\n\r\n&lt;#------------variables you need to change---------------#&gt;\r\n$servers = @(&#039;server1&#039;,&#039;server2&#039;);\r\n$path = &#039;C:\\Where_You_Want_The_Files\\system_info\\&#039;;\r\n&lt;#-------------------------------------------------------#&gt;\r\n\r\nforeach ($s in $servers)\r\n{\r\n  #------as long as we can connect to the machine, get the system info--------\r\n  if((Test-Connection -Cn $s -BufferSize 16 -Count 1 -ea 0 -quiet))\r\n  {\r\n        $filepath = $path + $s +&#039;.NFO&#039;;        \r\n        $cmd = &quot;C:\\windows\\system32\\msinfo32.exe&quot;;\r\n        $args = &quot;\/computer $s \/nfo $filepath \/categories +all&quot;;\r\n\r\n        #if you can connect to the server, gather and save sysinfo\r\n        Start-Process $cmd $args -Wait; \r\n\r\n  }\r\n  else\r\n  {\r\n        &quot;Cannot connect - $s&quot;\r\n  }\r\n    \r\n}<\/pre>\n<p>With this script you can generate system information files and save them to a specified location. It makes sure a connection can be made to the server first, and then outputs the file. The files are created one at a time, so if you pass in a longer list of servers, you shouldn&#8217;t crash your machine. From my testing, this will take some time to run as these files don&#8217;t output quickly. Despite that, the output is worth it. This can be modified to pull your list of servers from a file or from a Central Management Server (CMS) instance.<\/p>\n<p>Hope you find this useful. Happy PowerShellin&#8217; \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After whining about not blogging enough, I am going to do something about this. Whether it is PowerShell or SQL, simple or complex, I know that others can benefit from my knowledge and expand their skill sets. And you are &hellip; <a href=\"http:\/\/www.sqlkitten.com\/?p=263\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[70,69,6,3,1],"tags":[23,27,22,71],"_links":{"self":[{"href":"http:\/\/www.sqlkitten.com\/index.php?rest_route=\/wp\/v2\/posts\/263"}],"collection":[{"href":"http:\/\/www.sqlkitten.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sqlkitten.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sqlkitten.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sqlkitten.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=263"}],"version-history":[{"count":10,"href":"http:\/\/www.sqlkitten.com\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":276,"href":"http:\/\/www.sqlkitten.com\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions\/276"}],"wp:attachment":[{"href":"http:\/\/www.sqlkitten.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sqlkitten.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sqlkitten.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}