How to find out if a printer or printer port is installed?


i developing script installs printers based on input csv file.  file works great long first time being run.  having trouble in cases running script on computers have 1 or more printers or printer ports installed trying install script.

so trying generate if test see if various printers , printer ports present.

here little test script have created trying see if given printer port installed:

-------

  $portname = "10.1.2.68_1"  $ports = get-wmiobject -class win32_tcpipprinterport | select-object name    if ($ports -contains $portname)  {  	write-host "found port" $portname  }  else  {  	write-host "didn't find" $portname  }  


-------

if run "get-wmiobject -class win32_tcpipprinterport | select-object name" on computer, output:

name  ----  10.1.2.68  10.1.2.68_1


however, when run first script on computer, receive message "didn't find 10.1.2.68_1".

i presume problem $ports variable contains object , $portname variable contains string.  guessing need turn $ports collection of strings...  right?  , if so, how that?  feel there easy way accomplish missing.

select-object -expandproperty name


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...