简体   繁体   English

正在使用Powershell中的QueryHistory来查询远程计算机上的Windows更新

[英]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: 我仍然无法弄清楚,但是我想出的最后一种方法是:

  1. Write a ps1 script with the code needed to run QueryHistory 使用运行QueryHistory所需的代码编写ps1脚本
  2. 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 
  3. 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" 
  4. now write the code that reads the first ps1 you've written, puts it in a string and encodes it in base64 (that's what is $ps_command_stringEncoded in the code block above) 现在编写代码,读取您编写的第一个ps1,将其放在字符串中并在base64中编码(这就是上面的代码块中的$ps_command_stringEncoded
  5. wait the process to end, then retrieve the output file. 等待过程结束,然后检索输出文件。

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.

相关问题 如何使用Powershell在远程计算机上添加Windows防火墙端口例外? - How to add a windows firewall port exception on a remote machine using powershell? 使用python将文件从本地计算机传输到远程Windows服务器 - Transfer file from local machine to remote windows server using python 无法使用远程Windows计算机上的“复制”命令复制文件夹 - Unable to Copy folders using Copy command from a remote windows machine 是否可以在远程 Windows 机器上创建性能计数器? - Is it possible to create a performance counter on a remote Windows machine? 使用staf将文件从linux复制到远程Windows机器 - Copy file from linux to remote windows machine using staf 从 Node.js 代码在 Windows 远程机器上运行 powershell 脚本 - Run powershell script on windows remote machine from Node.js code 使用 RCP 或 FTP 将文件从远程 unix 机器复制到本地 windows 机器上 - Using RCP or FTP to copy files from a remote unix machine onto a local windows machine 使用批处理脚本将数据从本地计算机传输到远程计算机。是否可以..? - transfer the data from local machine to remote machine by using batch script.Is it possible or not..? 使用Java将文件从本地窗口机器复制到远程Windows机器 - Copy files from local window machine to remote windows machine using java powershell windows 缺少更新 - powershell windows missing updates
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM