我目前正在寻找网络上的所有 SolidWorks 许可证信息。
我需要帮助编写一个 PowerShell 脚本来查看 CSV/TXT 文件中的主机列表,然后执行以下命令,将结果保存为 CSV 格式,其中包含计算机名称、SolidWorks 许可证注册表项。
这是我正在使用的命令:
Invoke-Command -ComputerName NAME -Command {Get-ItemProperty -Path HKLM:\SOFTWARE\SolidWorks\Licenses}
默认情况下。SolidWorks 将其许可信息存储在以下注册表路径中
COMPUTERNAME\HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\Licenses\Serial Numbers\Solidworks
答案1
类似这样的事情会给你一个起点:
#Get computers from text file. 1 compute per line
$myComputerList = Get-Content C:\Installs\computerList.txt
#Loop Through Array
ForEach ($computer in $myComputerList) {
#Execute a command on the computer
Invoke-Command -ComputerName $computer -ScriptBlock {
#This is the command to execute
#Grab the registry value you want and hold it in a variable
$value = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" -Name ProductName
#grab the machine name you're working on
$computerName = $env:COMPUTERNAME
#comma separate them and spit them out to a file. This can be a UNC path on a network share
($computerName + "," + $value) | Out-File -FilePath C:\Installs\Output.csv -Append
}
}
您可以对此进行各种添加,例如处理多个注册表值、在连接之前测试机器是否已打开、处理访问错误和无法联系的机器等 - 但由于这不是脚本编写服务 - 我只是为您提供了一个简短的起点