by smokeypt2 at 2013-01-07 01:54:17
Hi All,by RichardSiddaway at 2013-01-07 07:36:00
Im having a slight problem with the script below.
Basically I have a list of printers with the IP in the 000.000.000.000 (big endian format I think??) in a text file, and I cant seem to get the correct IP to automatically map a printer on the print server.
The variable $Check comes back null, I have played around but can only seem to get either all the IP’s from the file, or nothing at all.
Does anyone know a way of selecting just an IP that matches the local host from a text file, and passes it back as a variable so it can map the printer?
This is what I have so far:
[code2=powershell]$ip = (Get-WmiObject -class win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"').ipaddress[0] | %{"{0:000}.{1:000}.{2:000}.{3:000}" -f
@([int]$.split('.'))}
$ip1 = $ip.Substring(4,7)
Write-Host $ip1
$Check = Get-Content "C:\PRINTERINV.csv" | Where-Object {$ -like $IP1 }
Write-Host $Check
#$String=[string]::join("`n", (Get-Content "C:\PRINTERINV.csv"))
#$Check = $String.contains($ip1)
#$PrinterPath = $Path + $String
#$net = new-Object -com WScript.Network
#$net.AddWindowsPrinterConnection($PrinterPath)
#Write-Host $String
#Write-Host $PrinterPath[/code2]
As you can see I have tried a couple of things and its still foxing me, any help would be gratefully appreciated
Kind Reagrds,
Sean,
Working through your code I got $ip containing 192.168.000.027
This means you substring is testing on 168.000
is this what you intended?
I suspect that the -like is not set properly in
$Check = Get-Content "C:\PRINTERINV.csv" | Where-Object {$_ -like $IP1 }
I would have expected
$Check = Get-Content "C:\PRINTERINV.csv" | Where-Object {$_ -like "$IP1" }
Can you post a couple of lines of the text file containing the printer information