I am hoping someone out there can give me a hand with this, I am close to figuring out but new to PowerShell...what else is new! In the $variable from reading in a text file, I have lines of text, each line has several columns, seperating the columns are spaces and tabs. What I want to do is replace the spaces and tabs with just one tab and delete everything after the "/" including the "/". Is this possible? Here is a sample, the "!" are the sapces and "*" are tabs. The amount of spaces and tabs varies between lines...
Example:
# Computer information # Column 1 computer name # Column 2 IPaddress # Column 3 Parent AD #
comp-79345-sdc!!!!!!**192.168.1.1/24!!!!!!***ads-23457-sda comp-79346-sdc!!!!!!!**192.168.1.2/24!!!!!!!!!**ads-23457-sda
Here is the code I have come up with to replace spaces and tabs with a "+" and delete all the lines with "#" in front. I can also out put to a new file.
$NetDef = Cat -path ("c:\Config-dir\Config-data\Net-def\network*.txt") | ForEach-Object {$_ -replace "\s","+"} | where { $_ -notlike "*#*"} $NetDef | Out-File C:\config-dir\Config-data\DNSNetDef.txt
Any help would be greatly appreciated!
Thanks. |