从远程计算机获取 powershell 中 .dll 的文件版本
我正在尝试在多台服务器上使用 Powershell 远程获取 dll 的文件版本,并将服务器名称、dll 版本和 dll 文件位置写入 csv 或 html 报告。问题是某些服务器是 Win 2003 和 Win 2008。因此该文件可能驻留在例如 C:\Program Files\WinZip\WZCAB.DLL 或 C:\Program Files (x86)\WinZip\WZCAB.DLL 中。该脚本将检查一个位置,如果不存在,则会检查另一个位置,然后将其写出。有人可以帮我吗?
只是几件事 - 该脚本将用于访问 2003 和 2008 年的 200 多个服务器或 VM。2003 年它需要 Powershell 2.0,2008 年它将及时启用远程处理。我在想也许我需要利用 WMI。我还有另外两个脚本,它们利用 WMI 来获取补丁和重新启动时间。我尝试了 Ravikanth 脚本(再次感谢您),但在传递服务器的 txt 文件时出现以下错误 - 一个或多个计算机名称无效。如果您尝试传递 Uri,请使用 -ConnectionUri 参数或传递 Uri 对象而不是字符串。同样,由于我不会在每台服务器上启用远程处理,是否还有其他方法可以做到这一点?我修改了 Ravikanth 脚本(如下)并在本地尝试过,效果很好。当我远程尝试时,却没有。有什么想法吗?
$servers = "D:\scripts\winzip\servers.txt"
$x86Path = 'C:\Program Files (x86)\WinZip\WZCAB.DLL'
$x64Path = 'C:\Program Files\WinZip\WZCAB.DLL'
foreach ($computername in $servers){
if (Test-Path $x86Path) {
(Get-Item $x86Path | Select -ExpandProperty VersionInfo).FileVersion
} elseif (Test-Path $x64Path) {
(Get-Item $x64Path | Select -ExpandProperty VersionInfo).FileVersion
}
}
I am trying to get the file version of a dll remotely using Powershell on several servers and have write the server name, dll version, and dll file location to a csv or html report. The catch is some of the servers are Win 2003 and Win 2008. So the file may reside in for example C:\Program Files\WinZip\WZCAB.DLL or C:\Program Files (x86)\WinZip\WZCAB.DLL. The script would check one location and if it did not exist it would check the other and then write it out. Can anyone help me out?
Just a few things - This script will be used to access 200+ servers or VM's both 2003 and 2008. On 2003 it needs Powershell 2.0 and 2008 it will be timely to enable remoting. I was thinking maybe I need to utilize WMI. I have two other scripts that utilize WMI to get patches and reboot times. I did though try Ravikanth script (thank you again) and got the following error when passing a txt file of servers - One or more computer names is not valid. If you are trying to pass a Uri, use the -ConnectionUri parameter or pass Uri objects instead of strings. Again since I will not be enabling remoting on each server, is there another way of doing this? I modified Ravikanth script (below) and tried it locally, works greats. When I try it remotely, it does not. Any thoughts?
$servers = "D:\scripts\winzip\servers.txt"
$x86Path = 'C:\Program Files (x86)\WinZip\WZCAB.DLL'
$x64Path = 'C:\Program Files\WinZip\WZCAB.DLL'
foreach ($computername in $servers){
if (Test-Path $x86Path) {
(Get-Item $x86Path | Select -ExpandProperty VersionInfo).FileVersion
} elseif (Test-Path $x64Path) {
(Get-Item $x64Path | Select -ExpandProperty VersionInfo).FileVersion
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在这些计算机上启用了远程处理:
这是执行此操作的 WMI 方式:
这只是您需要的一部分。您需要放置一个 try-catch 块以确保在该路径中找不到文件时处理错误。我会把它留给你的研发部门。 D .
If you have remoting enabled on those computers:
This is the WMI way of doing it:
This is only part of what you need. You need to put a try-catch block to make sure you handle the errors in case the file is not found at that path. I will leave that for your R & D.
使用
Test-Path
cmdlet 查看该路径是否存在。如果没有,请使用备用路径。Program Files 路径的差异并非来自 Win 2003 或 2008,而是来自操作系统是 32 位还是 64 位以及应用程序支持 32 位还是 64 位。
Use the
Test-Path
cmdlet to see if the path exists. If not use the alternate path.And the difference in the Program Files path doesn't arise from Win 2003 or 2008, but from whether the OS is 32-bit or 64-bit and the application has 32bit or 64bit support.