该脚本看起来有效,但我遇到了无法解决的问题。当我运行脚本时,它会创建一个文本文件,但打印机部分查找中的属性是引用我的计算机而不是它应该搜索的计算机。
我已将脚本放在下面,因为我不知道它是如何引用我的机器的。保存的文本文件正确地将自己保存为正确的计算机,但我对脚本不信任,因为它引用了我的机器。
它在文本文件中引用我的计算机的部分是
The printer has been found! Location : Name : Upload to Doc PrinterState : 0 PrinterStatus : 3 ShareName : SystemName : 1919WLB835 ← this is wrong, it should be the machine in the loop, not my machine
输入错误计算机名称的部分是
$Printer = gwmi Win32_Printer -Filter { name = "Upload to Doc" }
以下是整个脚本:
Import-Module PKI
$DocvelocityDesktop = gwmi Win32_Product -Filter { Name like "%DocVelocity Desktop%" }
$DocvelocityAddin = gwmi Win32_Product -Filter { Name = "Doc External Add-In for BytePro 1.0.16.0" }
$ByteProVer = gwmi Win32_Product -Filter { Name = "BytePro Enterprise" }
$Printer = gwmi Win32_Printer -Filter { name = "Upload to Doc" }
$CertStore = New-Object System.Security.Cryptography.X509Certificates.X509Store "\\$ComputerName\TrustedPublisher", "LocalMachine"
$CertStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
if ($Printer) {
Write-Host The "Printer has been located"
"The printer has been found!" | Out-File "c:\temp\$Computername.txt" -Append -Force
$Printer | Out-File "c:\temp\$Computername.txt" -Append -Force
} else {
Write-Host "Fail. Please install the printer cert for Capsilon"
"Fail. Please install the printer cert for Capsilon" | Out-File "c:\temp\$Computername.txt" -Append -Force
}
if ($DocvelocityDesktop) {
Write-Host The "DocVelocity Desktop has been found."
"The DocVelocity Desktop App was found!" | Out-File "c:\temp\$Computername.txt" -Append -Force
$DocvelocityDesktop | Out-File "c:\temp\$Computername.txt" -Append -Force
} else {
Write-Host "Fail. Please install the DocVelocity Desktop App"
"Fail. Please install the DocVelocity Desktop App" | Out-File "c:\temp\$Computername.txt" -Append -Force
}
if ($DocvelocityAddin) {
Write-Host The "DocVelocity Addin has been found."
"The DocVelocity Addin was found!" | Out-File "c:\temp\$Computername.txt" -Append -Force
$DocvelocityAddin | Out-File "c:\temp\$Computername.txt" -Append -Force
} else {
Write-Host "Fail. Please install the DocVelocity Addin"
"Fail. Please install the DocVelocity Addin" | Out-File "c:\temp\$Computername.txt" -Append -Force
}
if ($ByteProVer) {
Write-Host The "BytePro has been found."
"The BytePro App was found!" | Out-File "c:\temp\$Computername.txt" -Append -Force
$ByteProVer.Version | Out-File "c:\temp\$Computername.txt" -Append -Force
} else {
Write-Host "Fail. Please install Bytepro App"
"Fail. Please install the Bytepro App" | Out-File "c:\temp\$Computername.txt" -Append -Force
}
foreach ($Cert in $CertStore.Certificates) {
if ($Cert.Subject -eq "CN=Capsilon Corporation, O=Capsilon Corporation, L=San Francisco, S=California, C=US" -and $Cert.Thumbprint -eq "B03318F507A687362261165ABD906277D122E9F1") {
Write-Host "We have the cert for Capsilon Printer. "
"The cert we need was found!" | Out-File "c:\temp\$Computername.txt" -Append -Force
$Cert | Out-File "c:\temp\$Computername.txt" -Append -Force
}
}
$CertStore.Close()
} else {
$Computername | Out-File c:\temp\dead_machines.txt -Force -Append
}
}