Djentacodic

Update-ServerFiles.ps1

Apr 12th, 2024
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.85 KB | Source Code | 0 0
  1. [CmdletBinding()]
  2. Param(
  3.     [Parameter(Mandatory)]
  4.     [ValidateSet('IntuneMigration','IntuneRejoin')]
  5.     [String[]]$Source
  6. )
  7.  
  8. #region: functions
  9. Function Copy-ItemProgress {
  10.     Param(
  11.         [Parameter(Mandatory)][String]$Src,
  12.         [Parameter(Mandatory)][String]$Dest
  13.     )
  14.  
  15.     [Object]$FSO = Get-ChildItem -LiteralPath $Src -File -Recurse -Force
  16.     [String]$ChildPath = Split-Path -Path $Src -Leaf
  17.     [UInt32]$TotalFiles = $FSO | Measure-Object | Select-Object -ExpandProperty Count
  18.     [UInt32]$FileCount = 0
  19.  
  20.     $FSO | ForEach-Object {
  21.         [UInt16]$Percent = [math]::Truncate($FileCount / $TotalFiles * 100)
  22.         [String]$SourceFilePath = $_.FullName
  23.         $SourceFilePath -match "$ChildPath.*" | Out-Null
  24.         [String]$MatchString = $Matches[0]
  25.         [String]$DestinationFilePath = "${Dest}\${MatchString}"
  26.         $MatchString -match "\\.*" | Out-Null
  27.  
  28.         $ProgressParam = @{
  29.             Activity            = "Uploading files to ${Dest}\${ChildPath}..."
  30.             Status              = "${Percent}% Complete"
  31.             CurrentOperation    = "Copying [$($Matches[0].Substring(1))]"
  32.             PercentComplete     = $Percent
  33.         }
  34.  
  35.         Write-Progress @ProgressParam
  36.  
  37.         if (!(Test-Path (Split-Path -Path $DestinationFilePath -Parent))) {
  38.             mkdir $(Split-Path -Path $DestinationFilePath -Parent) | Out-Null
  39.         }
  40.  
  41.         Copy-Item -Path "$SourceFilePath" -Destination "$DestinationFilePath" -Force | Out-Null
  42.         $FileCount++
  43.     }
  44.     Write-Progress @ProgressParam -Completed
  45.     Remove-Variable -Name FSO,ChildPath,TotalFiles,FileCount,Percent,MatchString,SourceFilePath,DestinationFilePath,ProgressParam
  46. }
  47. #end functions
  48.  
  49. [String[]]$Destination = @( '\\dc1vc1fs01\Apps','\\exp-fs05is\PC')
  50.  
  51. $Source | ForEach-Object {
  52.     [String]$SourcePath = "$global:IntuneScripts\$_"
  53.     If (Test-Path -Path $SourcePath -PathType Container) {
  54.         $Destination | ForEach-Object {
  55.             Copy-ItemProgress -Src $SourcePath -Dest $_
  56.         }
  57.     }
  58. }
  59. Remove-Variable -Name SourcePath,Destination -Force
Add Comment
Please, Sign In to add comment