onepc

查看远程打印机的一些代码

#查看打印机的端口

$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 "按任意键退出……"



分类:

技术点:

相关文章:

  • 2021-09-26
  • 2021-11-04
  • 2022-12-23
  • 2021-07-20
  • 2022-01-13
  • 2022-02-17
  • 2021-07-12
  • 2021-12-15
猜你喜欢
  • 2021-11-30
  • 2021-12-27
  • 2021-10-14
  • 2021-08-03
  • 2021-12-10
  • 2022-01-29
  • 2021-11-20
相关资源
相似解决方案