I have below script to input server host name or IP which returns the text files for those host names/IP as output.
Then i have to manually delete those host names from the text files.
How can I tweak the script to directly delete that host name from text file and save it ? Also instead of one host name as input can we put down a list of servers to search and delete with success/failure log ?
If someone can suggest how to achieve this.
Thanks .
[string]$Server = Read-Host -Prompt ‘Input the server name to search and hit Enter’
#[string]$Path1 = \servername.com\d$
[string]$Path = “\servername.com\d$”
#Do {
write-host $Server
write-host “Searching for the Server $Server in $Path …search is in progress… `n `n” -foregroundcolor green
Write-Host "$Server is located in the following paths : " -foregroundcolor magenta
$PathArray | ForEach-Object {$_}
if (!$PathArray) { Write-Host “Server does not exist in the selected path. Please search in other locations. `n” -foregroundcolor Red } #write-host $PathArray #write-host "`n Time taken to search is : $time minutes. " -foregroundcolor green
Please use the pre tags to format your code. I’d recommend breaking things up a bit, collect the files, loop thru the files, loop thru the lines in the file, if a match is found overwrite the file.