[英]Is using QueryHistory from powershell to query windows updates on remote machine possible
before someone is thinking, hey this question is easy to answer (=> yes...) please keep on reading... 在有人思考之前,嘿这个问题很容易回答(=>是...)请继续阅读...
i know, we can get an instance of "Microsoft.Update.Session
" from a remote machine with (for example) the following code 我知道,我们可以使用(例如)以下代码从远程计算机上获取
"Microsoft.Update.Session
”的实例
[activator]::CreateInstance([type]::GetTypeFromProgID("Microsoft.Update.Session",$ComputerName))
and this works for other actions like search for Updates that are installed IsInstalled = 0
. 这适用于其他操作,例如搜索已安装
IsInstalled = 0
更新。
To get a full list of all updates (also pending etc.) there are a lot of examples on the internet, even here on stackoverflow . 为了获得所有更新的完整列表(还有待处理的信息等),互联网上有很多示例,即使在stackoverflow上也是如此 。
they all write to do the following 他们都写来做以下事情
$Session = [activator]::CreateInstance([type]::GetTypeFromProgID("Microsoft.Update.Session",$ComputerName))
$Searcher = $Session.CreateUpdateSearcher()
$TotalUpdatesCount = $Searcher.GetTotalHistoryCount()
$TotalUpdates = $Searcher.QueryHistory(0, $TotalUpdatesCount)
And it seems that it is working because there is no error.... and we have a nice (big) list of Updates... 似乎它正在工作,因为没有错误....而且我们有一个不错的(大)更新列表...
My problem is, the Result of QueryHistory(int, int)
returns is always the same... no matter what $ComputerName
i have entered at the CreateInstance(...GetTypeFromProgID(..., $ComputerName))
part 我的问题是,
QueryHistory(int, int)
返回的结果始终相同...不管我在CreateInstance(...GetTypeFromProgID(..., $ComputerName))
部分输入了什么$ComputerName
And no one on all the sites who are giving examples is mentioning this, i believe they all used the code locally
because in that scope it is returning the correct values... 在所有提供示例的站点上, 没有人提到这一点,我相信他们都在
locally
使用了该代码locally
因为在该范围内,它返回的是正确的值...
after investigating deeper and reading the MSDN i found the following statement on https://msdn.microsoft.com/en-us/library/windows/desktop/bb394842(v=vs.85).aspx 在深入研究并阅读了MSDN之后,我在https://msdn.microsoft.com/en-us/library/windows/desktop/bb394842(v=vs.85).aspx上找到了以下语句
Note that QueryHistory supports per-machine updates only.
To sum um, 总而言之,
my Question is : Is it Possible to use QueryHistory in Powershell to get a list of Updates on a remote machine (without invoke... that requires PSRemoting... / or tools like psexec...)
and if yes, how? 我的问题是 :是否可以在Powershell中使用QueryHistory来获取远程计算机上的更新列表
(without invoke... that requires PSRemoting... / or tools like psexec...)
,如果可以,如何?
Same problem here. 这里同样的问题。 I still can't figure it out, but the last approach I came up with is:
我仍然无法弄清楚,但是我想出的最后一种方法是:
write another ps1 script that creates a process on the remote machine using 编写另一个ps1脚本,该脚本使用以下命令在远程计算机上创建进程
Invoke-WmiMethod -class Win32_process -name Create -ArgumentList $cmd_command_string -Computername $computerName -erroraction Stop -Credential $credential
this is $cmd_command_string
: it basically opens a cmd that fires a powershell 这是
$cmd_command_string
:它基本上会打开一个cmd,该cmd会触发powershell
$cmd_command_string="cmd /C powershell.exe -EncodedCommand " + $ps_command_stringEncoded + " >> C:\\Windows\\output.log"
$ps_command_stringEncoded
in the code block above) $ps_command_stringEncoded
) Seems legit to me, but someway I can't make it work. 在我看来是合法的,但无论如何我无法使其正常工作。 If somebody wants to give it a try...
如果有人想尝试一下...
EDIT : I ended up copying a VBS script on the remote machine, calling QueryHistory from that script, writing output on file, retrieving that remote file back. 编辑 :我最终在远程计算机上复制了VBS脚本,从该脚本调用QueryHistory,在文件上写入输出,然后取回该远程文件。 Dirty, but it works.
脏,但是可以用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.