Friday, October 28, 2011

How To's : Edit Hosts File Remotely Part 1



Many of us want to edit hosts file remotlel or easily to fun with others. Here is the trick how to edit it remotely.

Input File: Servers.csv – This file contains server name or IP address. List all addresses you want to add in hosts file.You just have to create this files in any folder and save as Servers.csv 
Then Click on Start button and type Windows Powershell and Click on first Result "Windows PowerShell ISE".

In Power Shell type following script and save as "Edit_Hosts_File.ps1" (Without Quotes).
Script
#www.sivarajan.com 
#blogs.sivarajan.com 
#Updating HOSTS file using PowerShell Script 
 
CLS 
Import-CSV "C:\Scripts\Servers.csv" | % {  
    $Server = $_.ServerName 
    $adminpath = Test-Path "\\$Server\admin$" 
    If ($adminpath -eq "True") 
        { 
         $hostfile = "\\$Server\c$\Windows\System32\drivers\etc\hosts" 
         Write-Host –NoNewLine "Updating $Server..." 
         "10.10.10.100`tMyhost" | Out-File $hostfile -encoding ASCII -append 
         Write-Host "Done!"  
          
            
        } 
    Else  
        { 
            Write-Host -Fore Red "Can't Access $Server" 
        } 
    } 
 Output – You will see the status update on the screen as displayed in the following screenshot:
Download Text file from here or here

Related Posts Plugin for WordPress, Blogger...