#查看打印机的端口
$class = "win32_printer"
$class1 = "Win32_TcpIpPrinterPort"
write-host "查看远程计算机所安装的打印机以及TCP/IP端口"
while($true)
{
$computer = read-host "请输入计算机名或者IP地址"
if($computer -eq "exit")
{
break
}
write-host $computer"所安装的打印机列表:"
$wmi = Get-WmiObject -Class $class -computername $computer
#format-table -Property name, systemName, shareName -groupby driverName -inputobject $wmi -autosize
$wmi | Format-Table name,ShareName,SystemName -AutoSize
Get-WmiObject -Class $class1 -computername $computer | format-table hostaddress,Name,Queue
}
#扫描共享打印机
#function scanping {
# $ping = New-Object system.Net.NetworkInformation.Ping
# $ping.Send($args).status
#}
function getcomname($ipaddress)
{
[System.Net.IPHostEntry]$ipobj = [System.Net.dns]::gethostbyaddress($ipaddress)
write-host -foregroundcolor red $ipobj.hostname
}
function scanprint($comname)
{
$pingResult = Test-Connection -ComputerName $comname -Count 1 -Quiet
if ($pingResult)
{
Trap {"Failed to connect $comname due to "+$error[0];Continue}
#Write-Host -foregroundcolor green "$comname:"
write-host $comname
Get-WmiObject -class win32_share -computername $comname -ErrorAction SilentlyContinue | where {$_.type -eq 1}
} else {
Write-Warning "Failed to connect : $comname"
}
}
write-host -ForegroundColor red "扫描共享打印机,输入前面三位子网地址(eg:192.168.15.)"
$subnet = read-host
write-host -ForegroundColor red "正在扫描……"
for($i=2;$i -lt 254; $i++)
{
$suball = $subnet+$i
scanprint($suball)
}
write-host -ForegroundColor red "扫描完成!"
$input = read-host "按任意键退出……"