Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [CmdletBinding()]
- Param(
- [Parameter(Mandatory)]
- [ValidateSet('IntuneMigration','IntuneRejoin')]
- [String[]]$Source
- )
- #region: functions
- Function Copy-ItemProgress {
- Param(
- [Parameter(Mandatory)][String]$Src,
- [Parameter(Mandatory)][String]$Dest
- )
- [Object]$FSO = Get-ChildItem -LiteralPath $Src -File -Recurse -Force
- [String]$ChildPath = Split-Path -Path $Src -Leaf
- [UInt32]$TotalFiles = $FSO | Measure-Object | Select-Object -ExpandProperty Count
- [UInt32]$FileCount = 0
- $FSO | ForEach-Object {
- [UInt16]$Percent = [math]::Truncate($FileCount / $TotalFiles * 100)
- [String]$SourceFilePath = $_.FullName
- $SourceFilePath -match "$ChildPath.*" | Out-Null
- [String]$MatchString = $Matches[0]
- [String]$DestinationFilePath = "${Dest}\${MatchString}"
- $MatchString -match "\\.*" | Out-Null
- $ProgressParam = @{
- Activity = "Uploading files to ${Dest}\${ChildPath}..."
- Status = "${Percent}% Complete"
- CurrentOperation = "Copying [$($Matches[0].Substring(1))]"
- PercentComplete = $Percent
- }
- Write-Progress @ProgressParam
- if (!(Test-Path (Split-Path -Path $DestinationFilePath -Parent))) {
- mkdir $(Split-Path -Path $DestinationFilePath -Parent) | Out-Null
- }
- Copy-Item -Path "$SourceFilePath" -Destination "$DestinationFilePath" -Force | Out-Null
- $FileCount++
- }
- Write-Progress @ProgressParam -Completed
- Remove-Variable -Name FSO,ChildPath,TotalFiles,FileCount,Percent,MatchString,SourceFilePath,DestinationFilePath,ProgressParam
- }
- #end functions
- [String[]]$Destination = @( '\\dc1vc1fs01\Apps','\\exp-fs05is\PC')
- $Source | ForEach-Object {
- [String]$SourcePath = "$global:IntuneScripts\$_"
- If (Test-Path -Path $SourcePath -PathType Container) {
- $Destination | ForEach-Object {
- Copy-ItemProgress -Src $SourcePath -Dest $_
- }
- }
- }
- Remove-Variable -Name SourcePath,Destination -Force
Add Comment
Please, Sign In to add comment