Help with Text file reading

Welcome Forums General PowerShell Q&A Help with Text file reading

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 6 years, 10 months ago.

  • Author
  • #5407

    Points: 0
    Rank: Member

    by smokeypt2 at 2013-01-07 01:54:17

    Hi All,

    Im having a slight problem with the script below.

    Basically I have a list of printers with the IP in the (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

    $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

    #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,

    by RichardSiddaway at 2013-01-07 07:36:00

    Working through your code I got $ip containing
    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

The topic ‘Help with Text file reading’ is closed to new replies.