powershell 验证GPO IP打印机是否可以ping通
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 验证GPO IP打印机是否可以ping通相关的知识,希望对你有一定的参考价值。
$PrinterGPOs = Get-GPO -All | Where-Object {$_.DisplayName.StartsWith("C - Printer - ")} | Sort-Object displayName
$i = 0
foreach ($PrinterGPO In $PrinterGPOs) {
$Properties = @{
GpoName = $null
IPv4SourceAddress = $null
IPv4APrinterddress = $null
Pingable = $null
}
$Properties.GpoName = $PrinterGPO.DisplayName
Write-Progress -Id 1 -Activity "Analyzing IP Printer GPO" -Status "$($Properties.GpoName)" -PercentComplete (($i / $PrinterGPOs.Count) * 100)
$SettingsXml = [XML](Get-GPOReport -Guid $PrinterGPO.Id -ReportType Xml) | Where-Object {$_.GPO.Computer.ExtensionData -ne $null}
$PortPrinters = [System.Net.IPAddress[]]$SettingsXml.GPO.Computer.ExtensionData.Extension.Printers.PortPrinter.name | Sort-Object
foreach ($PortPrinter In $PortPrinters) {
$Properties.IPv4SourceAddress = (New-Object Net.Sockets.TcpClient "$([DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name)", 135).Client.LocalEndPoint.Address.IPAddressToString
$Properties.IPv4APrinterddress = $PortPrinter.IPAddressToString
Write-Progress -Id 2 -ParentId 1 -Activity "Checking if IPv4 address is pingable" -Status "$($Properties.IPv4APrinterddress)"
if ($Properties.IPv4APrinterddress) {
$Properties.Pingable = Test-Connection -ComputerName $Properties.IPv4APrinterddress -Count 1 -Quiet
}
}
$obj = New-Object -TypeName PSObject -Property $Properties
Write-Output $obj
$i++
}
以上是关于powershell 验证GPO IP打印机是否可以ping通的主要内容,如果未能解决你的问题,请参考以下文章
powershell GPO
powershell 广告获得的GPO
powershell AD-删除 - GPO
使用PowerShell 测试DNS
脚本powershell后当前用户的弹出消息
C++验证IP是否可PING与巨型帧设置(一零三)