I am developing a script that installs certain printers based on input from a CSV file. The file works great as long as it is the first time being run. I am having some trouble in some cases with running the script on computers that already have
one or more printers or printer ports installed that I am trying to install with this script.
So I am trying to generate an if test to see if various printers and printer ports are present.
Here is a little test script I have created that is trying to see if a given printer port is already installed:
$PortName="10.1.2.68_1"$Ports= Get-WmiObject -Class Win32_TCPIPPrinterPort | Select-Object Name
Write-Host "Found port"$PortName
Write-Host "Didn't find"$PortName
If I run "Get-WmiObject -Class Win32_TCPIPPrinterPort | Select-Object Name" on my computer, I get this as output:
However, when I run my first script on my computer, I receive the message "Didn't find 10.1.2.68_1".
I presume the problem is that $Ports is a variable that contains an object and $PortName is a variable that contains a string. So I am guessing that I need to turn $Ports into a collection of strings... is that right? And if so, how do
I do that? I feel like there is an easy way to accomplish this that I am just missing.
Microsoft is conducting an online survey to understand your opinion of the Technet Web site. If you choose to participate, the online survey will be presented to you when you leave the Technet Web site.