Determine PowerShell version remotely via WMI
I have searched here and elsewhere and could not find an answer, so here is my question.
What is the best way to determine PowerShell version on a remote computer using WMI?
Background
My task is to audit and update some 1000 servers to recent version of PowerShell. Some of them have PowerShell v1 and some do not have WinRM configured, so Invoke-command is not an option. PSExec is also not an option in this environment. This is why I need to use WMI for this task.
Any help would be appreciated.
EDIT:
After much research I'm still leaning towards WMI. In particular retrieving the file version of "powershell.exe". This seems to me to be the only way to cover all versions.
Code I have so far is here:
$path = "C:Windowssystem32WindowsPowerShellv1.0powershell.exe"
$query = "SELECT Version FROM CIM_DataFile WHERE Name = '$path'"
$PSFileVer = Get-WmiObject -Query $query -ComputerName $servername -Credential $creds
$BuildVer = [version]$PSFileVer.Version.Split()[0]
All I need now is a comprehensive list, mapping file version (build number) to powershell version. Any Ideas?
The solution from here is
$command = "ipconfig/all > C:tempresult.txt"
$cmd = "cmd /c $command"
Invoke-WmiMethod -class Win32_process -name Create -ArgumentList $cmd -ComputerName "remotepc"
sleep 1
Get-Content remotepcC$tempresult.txt
You can also do similar via this method. If you do so, you can't get the return value directly, u must redirect to a file.
You could setup share for the results instead of putting result on local machine
如果这有帮助,那就是命令:
$command = "powershell -command "+'"$PSVersionTable.PsVersion.Major | out-file c:tempversion.txt"'
链接地址: http://www.djcxy.com/p/29018.html