{"id":248,"date":"2008-01-23T01:00:31","date_gmt":"2008-01-23T09:00:31","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2008\/01\/23\/is-powershell-installed\/"},"modified":"2008-07-08T02:17:53","modified_gmt":"2008-07-08T10:17:53","slug":"is-powershell-installed","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2008\/01\/23\/is-powershell-installed\/","title":{"rendered":"Is PowerShell Installed?"},"content":{"rendered":"<p>By now you may have PowerShell installed on more than a few machines. Maybe you even have the PowerShell CTP installed somewhere.  Do you remember where you&rsquo;ve installed PowerShell? Could someone else have installed PowerShell on a system without your knowledge?  Perhaps an eager user?<\/p>\n<p>I put together a PowerShell function you can use to check if PowerShell is installed on a remote system.<\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">Function Get-PowerShellInstall {<br \/>\nParam ([string]$computer=&quot;localhost&quot;) <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">#registry hive constants<br \/>\n$HKLM=2147483650<br \/>\n$HKCU=2147483649<br \/>\n$HKCR=2147483648<br \/>\n$HKEY_USERS=2147483651 <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">#there is no provision for alternate credentials<br \/>\n$Reg = [WMIClass]&quot;\\$computer\\root\\default:StdRegProv&quot; <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">$basePath=&quot;software\\microsoft\\powershell\\1&quot;<br \/>\n$ShellPath=&quot;shellids\\Microsoft.PowerShell&quot;<br \/>\n$EnginePath=&quot;PowerShellEngine&quot; <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">$InstallPath=$reg.GetStringValue($HKLM,(Join-Path $basePath $ShellPath),&quot;path&quot;).svalue <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">#only get other values if able to get a value for $InstallPath<br \/>\nif ($InstallPath) { <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">    $Installed=$True<br \/>\n$ExecutionPolicy=$reg.GetStringValue($HKLM,(Join-Path $basePath $ShellPath),&quot;ExecutionPolicy&quot;).svalue<br \/>\n#if ExecutionPolicy key is missing then assume Restricted<br \/>\nif (-not $ExecutionPolicy) {<br \/>\n$ExecutionPolicy=&quot;Restricted&quot;<br \/>\n}<br \/>\n$PowerShellVersion=$Reg.GetStringValue($HKLM,(Join-Path $basePath $EnginePath),&quot;PowerShellVersion&quot;).svalue<br \/>\n$RunTimeVersion=$Reg.GetStringValue($HKLM,(Join-Path $basePath $EnginePath),&quot;RunTimeVersion&quot;).svalue <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">}<br \/>\nelse { <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">    $InstallPath=&quot;&quot;<br \/>\n$Installed=$False<br \/>\n$ExecutionPolicy=&quot;&quot;<br \/>\n$PowerShellVersion=&quot;&quot;<br \/>\n$RunTimeVersion=&quot;&quot; <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">} <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">$obj=New-Object PSObject<br \/>\n$obj | Add-Member -MemberType NoteProperty -Name &quot;Computer&quot; -Value $computer.ToUpper()<br \/>\n$obj | Add-Member -MemberType NoteProperty -Name &quot;Installed&quot; -Value $Installed<br \/>\n$obj | Add-Member -MemberType NoteProperty -Name &quot;InstallPath&quot; -Value $InstallPath<br \/>\n$obj | Add-Member -MemberType NoteProperty -Name &quot;ExecutionPolicy&quot; -Value $ExecutionPolicy<br \/>\n$obj | Add-Member -MemberType NoteProperty -Name &quot;Version&quot; -Value $PowerShellVersion<br \/>\n$obj | Add-Member -MemberType NoteProperty -Name &quot;RunTimeVersion&quot; -Value $RunTimeVersion <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">write $obj <\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">}<\/font><\/p>\n<p>Don&rsquo;t try to copy and paste the function from the blog entry as it screws up some formatting details.  I&rsquo;ve attached it as a text file.<\/p>\n<p>The script uses WMI  and the StdRegProv to remotely connect to a specified computer&rsquo;s registry. To accomplish this we create an instance of a WMIClass object using the [WMIClass] type adapter.<\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">$Reg = [WMIClass]&quot;\\$computer\\root\\default:StdRegProv<\/font>&quot;<\/p>\n<p>One drawback is that there is no way to specify alternate credentials so you can only connect to remote systems with your current credentials.<\/p>\n<p>Once connected we can read installation information from the registry. Instead of returning basic information, the function returns a custom object. When you run the function you should get a result like this:<\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">Computer        : LOCALHOST<br \/>\nInstalled       : True<br \/>\nInstallPath     : C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe<br \/>\nExecutionPolicy : RemoteSigned<br \/>\nVersion         : 1.0<br \/>\nRunTimeVersion  : v2.0.50727<\/font><\/p>\n<p>But because the function returns an object and can accept input you can do things like this:<\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">cat servers.txt | % { get-powerShellInstall $_ | where {$_.Installed}} | format-table Computer,InstallPath,ExecutionPolicy,Version -auto<\/font><\/p>\n<p>Now you should be able to easily find out where PowerShell is installed and how it is configured.<\/p>\n<div class=\"wlWriterSmartContent\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:eeca966d-0b5f-48aa-b333-8eea9ddacc78\" style=\"margin: 0px; padding: 0px; display: inline;\">Technorati Tags: <a href=\"http:\/\/technorati.com\/tags\/PowerShell\" rel=\"tag\">PowerShell<\/a>, <a href=\"http:\/\/technorati.com\/tags\/Registry\" rel=\"tag\">Registry<\/a>, <a href=\"http:\/\/technorati.com\/tags\/WMI\" rel=\"tag\">WMI<\/a>, <a href=\"http:\/\/technorati.com\/tags\/Scripting\" rel=\"tag\">Scripting<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>By now you may have PowerShell installed on more than a few machines. Maybe you even have the PowerShell CTP installed somewhere.  Do you remember where you&#8217;ve installed PowerShell? Could someone else have installed PowerShell on a system without your knowledge?  Perhaps an eager user?<\/p>\n<p>I put together a PowerShell function you can use to check if PowerShell is installed on a remote system.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-248","post","type-post","status-publish","format-standard","hentry","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=248"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/248\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}