Textfiles

It nice and easy to work with textfiles but sometimes they contain lines that get's it the way like blank lines or spaces.
To cleanup a textfile you can use powershell.
Let's say you type:

netsh dhcp show server

To list all the dhcp servers in your domain that have been authorized.
This text is copied into a textfile let's say, dhcpservers.txt
It will contain all those empty lines that are not needed when you want to use the textfile for querying those dhcp servers one by one with get-content dhcpservers.txt | etc etc

To get rid of those empty lines you would do:

(get-content \\servershare\sharename\scripts\dhcp_servers.txt) | where {$_ -ne ""} | out-file \\servershare\sharename\scripts\dhcp_servers.txt

on me

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License