PowerShell: Copy and rename file for to keep as a backup

Scenario:  You want to use PowerShell to make a backup of a specific file across many servers and store it locally.  We will perform this on a Web.Config file for IIS. The file once copied will be stored as C:SharebkupWebsvr1-wwwroot_web.config.

 

Script:

#Collect your Servers into a variable
$servers = "WebSvr1","WebSvr2","WebSvr3"

#Copy the file from the remote server to a local share

$Servers | %{
Copy-Item -Path "\$_c$inetpubwwwrootweb.config" -Destination "C:Sharebkup$_-wwwroot_web.config" 
}
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: