# Help with Text file reading

**URL:** <https://forums.powershell.org/t/help-with-text-file-reading/462>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/help-with-text-file-reading/462 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/help-with-text-file-reading/462/1 "2011-12-31T18:30:00Z")

</div>

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

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

> 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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:57pm UTC](https://forums.powershell.org/t/help-with-text-file-reading/462/2 "2024-05-16T20:57:53Z")

</div>

Closed on May 16, 2024, 8:57pm UTC


