SHARE
TWEET

Untitled

a guest Jun 16th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Copy-RCSSFile {
  2.  
  3. <#
  4. .SYNOPSIS
  5.     Copy files from a given path to a remote computer.
  6.  
  7. .PARAMETER ComputerName
  8.     Target remote computer
  9.  
  10. .PARAMETER Path
  11.     File path for the local file to be copied
  12.  
  13. .PARAMETER Destination
  14.     File path for the destination file on the target computer
  15.  
  16. .PARAMETER DestinationPath
  17.     Destination directory on the target computer
  18. #>
  19.  
  20. [CmdletBinding()]
  21.  
  22. param (
  23.  
  24.     [Parameter( Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True )
  25.     ]
  26.     [string]$computername,
  27.  
  28.     [Parameter( Mandatory=$True, ValueFromPipelineByPropertyName=$True )
  29.     ]
  30.     [string]$path,
  31.    
  32.     [Parameter( Mandatory=$True, ValueFromPipelineByPropertyName=$True )
  33.     ]
  34.     [string]$destination,
  35.  
  36.     [Parameter( ValueFromPipelineByPropertyName=$True )
  37.     ]
  38.     [string]$destinationfolder
  39.  
  40. ) # param
  41.  
  42. BEGIN {
  43.  
  44.     # Setting up DestinationFolder
  45.     Write-Verbose "Setting $destinationfolder variable"
  46.     $destinationfolder = "C:\_Code"
  47.  
  48. } #BEGIN
  49.  
  50. PROCESS {
  51.  
  52.     foreach ( $computer in $ComputerName ) {
  53.  
  54.         # Setting up Session to remote computer
  55.         Write-Verbose "Connecting to $computer to copy items"
  56.         $session = New-PSSession -ComputerName $computer
  57.        
  58.         Write-Verbose "Checking to see if $destinationfolder exists on $computer"
  59.  
  60.             If (-not (Test-Path -LiteralPath $destinationfolder)) {
  61.  
  62.                 Try {
  63.  
  64.                     Write-Verbose "Creating $destinationfolder on $computer"
  65.                     New-Item -Path $destinationfolder -ItemType Directory -ErrorAction Stop
  66.  
  67.                 } Catch {
  68.  
  69.                     Write-Error -Message "Unable to create directory $destinationfolder. Error was: $_" -ErrorAction Stop
  70.                
  71.                 }
  72.  
  73.             } Else {
  74.  
  75.                 Write-Verbose "Directory already exists"
  76.            
  77.             } # If
  78.  
  79.         Write-Verbose "Copying files to $computer"
  80.         Copy-Item -Path $path -Destination $destination -ToSession $session
  81.  
  82.         Write-Verbose "Closing $computer session"
  83.         Remove-PSSession -Session $session
  84.  
  85.     } # foreach
  86.  
  87. } #PROCESS
  88.  
  89. END {
  90.  
  91. } #END
  92.  
  93. } #function
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top