gpt4 book ai didi

powershell - 通过WMI远程确定PowerShell版本

转载 作者:行者123 更新时间:2023-12-02 23:27:42 25 4
gpt4 key购买 nike

我在这里和其他地方进行搜索,找不到答案,所以这是我的问题。

使用WMI在远程计算机上确定PowerShell版本的最佳方法是什么?

背景

我的任务是审核约1000台服务器并将其更新到最新版本的PowerShell。其中一些具有PowerShell v1,一些未配置WinRM,因此调用命令是不可选项。 在此环境中也不可选PSExec 。这就是为什么我需要为此任务使用 WMI 的原因。

任何帮助,将不胜感激。

编辑:

经过大量研究,我仍然倾向于WMI。特别是检索“powershell.exe”的文件版本。在我看来,这是涵盖所有版​​本的唯一方法。

我到目前为止的代码在这里:

$path = "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.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]

我现在需要的是一个完整的列表,将文件版本(内部版本号)映射到powershell版本。有任何想法吗?

最佳答案

here的解决方案是

$command = "ipconfig/all > C:\temp\result.txt"
$cmd = "cmd /c $command"

Invoke-WmiMethod -class Win32_process -name Create -ArgumentList $cmd -ComputerName "remotepc"
sleep 1
Get-Content \\remotepc\C$\temp\result.txt

您也可以通过 this方法执行类似操作。如果这样做,您将无法直接获取返回值,您必须将其重定向到文件。

您可以为结果设置共享,而不是将结果放在本地计算机上

关于powershell - 通过WMI远程确定PowerShell版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29665724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com