How to create a PowerShell script and use PowerShell to copy a file to a list of computers

Create the script in a plain text, save with a .PS1 file extension.

Run the script by entering the full path to the script (c:\scripts\myscript.ps1), or if it’s in the current directory, prefix it with a period followed by a backslash (.\myscript.ps1).

If the path to the script contains a space, enclose the full path in quotation marks and prefix the entire thing with an ampersand (for example: &"C:\my scripts\myscript.ps1").

make sure to set the correct execution policy using Set-ExecutionPolicy. To allow local scripts to run unsigned, run:
Set-ExecutionPolicy RemoteSigned

# computer list
$Computers = Read-Host "Enter Location Of TXT File"

# source file
$Source = Read-Host "Enter File Source"

# destination
$Destination = Read-Host "Enter File destination (windows\temp)"

# display to screen
Get-Content $Computers | foreach {Copy-Item $Source -Destination \\$_\c$\$Destination}


from SpiceWorks

Advertisements

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 )

Google+ photo

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

Connecting to %s