jeffharbert

Copy File if Computer Name Doesn't Match Specified Name

Apr 5th, 2017
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Written by Jeff Harbert, 4-5-2017
  2. ## This Powershell script copies a file from a remote computer if the computer name doesn't match a specified name.
  3. ## This allows the same script to run on multiple computers when only one computer contains a 'master'
  4. ## file of some kind, simplifying script version control.
  5. ## If the names do match the local file is used, but that will only happen on the specified computer.
  6.  
  7. ## Grab the computer name and assign it to a variable
  8. $computerName = $env:computername
  9.  
  10. ## Compare $computerName to a specified computer name, and copy a file if the names don't match.
  11. ## In this case, the computer name is ANTIGEN.
  12. If ($computerName -ne "ANTIGEN")
  13. {
  14. Copy-Item "\\ANTIGEN\path\to\file.txt" "C:\path\to\file.txt"
  15. }
  16.  
  17. ## The rest of the script (if any) that uses file.txt goes here.
Advertisement
Add Comment
Please, Sign In to add comment