![]() ![]() $path = Join-Path $using:cacheLocation $key $key = :: Join ( "", $using:destinationPath, $using:sourcePath, $expectedDestinationPath ) ). $uploadedItem = Get-Item $expectedDestinationPath Write-Verbose "$sourcePathType $expectedDestinationPath has been successfully created" Invoke-Command -ScriptBlock ( :: Create ( $using:throwTerminatingError ) ) -ArgumentList "DestinationPathNotCreatedFailure", $errorMessage, "InvalidData" $errorMessage = "Destination path $using:destinationPath could not be created" ![]() If ( ! ( Test-Path $expectedDestinationPath ) ) # Verify whether expectedDestinationPath was created Invoke-Command -ScriptBlock ( :: Create ( $using:throwTerminatingError ) ) -ArgumentList "CopyDirectoryOverFileFailure", $errorMessage, "InvalidData" $errorMessage = "Couldn't copy source path $using:sourcePath to $using:destinationPath : $($_.Exception)" Write-Debug "Copying $using:sourcePath to $using:destinationPath"Ĭopy-Item -path $using:sourcePath -Destination $using:destinationPath -Recurse -Force -ErrorAction Stop Write-Debug "ExpectedDestinationPath is $expectedDestinationPath" $expectedDestinationPath = Join-Path $using:destinationPath ( Split-Path $using:sourcePath -Leaf ) Invoke-Command -ScriptBlock ( :: Create ( $using:throwTerminatingError ) ) -ArgumentList "DestinationPathCannotBeFileFailure", $errorMessage, "InvalidData" $errorMessage = "Invalid parameter values: DestinationPath is file, but has to be existing directory." Throw-TerminatingError -errorMessage $errorMessage -errorCategory "InvalidData" -errorId "DestinationPathDoesNotExistFailure" $errorMessage = "Invalid parameter values: DestinationPath doesn't exist, but has to be existing directory." If ( ! ( Test-Path $using:destinationPath ) ) Invoke-Command -ScriptBlock ( :: Create ( $using:throwTerminatingError ) ) -ArgumentList "DestinationPathNotAccessibleFailure", $errorMessage, "InvalidData" $errorMessage = "Cannot access destination path $using:destinationPath with given Credential" ![]() Write-Debug "Create psdrive with destination path $using:destinationPath." $psDriveArgs = Name = ( :: NewGuid ( ) ) PSProvider = "FileSystem" Root = $using:destinationPath Scope = "Private" Credential = $credential } Write-Debug "Destination path $using:destinationPath is already accessible. If ( Test-Path $using:destinationPath -ErrorAction Ignore ) # Mount the drive only if credentials are specified and it's currently not accessible Write-Debug "SourcePath $using:sourcePath is of type: $sourcePathType" Invoke-Command -ScriptBlock ( :: Create ( $using:throwTerminatingError ) ) -ArgumentList "SourcePathDoesNotExistFailure", $errorMessage, "InvalidData" $errorMessage = "Source path $using:sourcePath does not exist." # Check whether source path is existing file or directory Invoke-Command -ScriptBlock ( :: Create ( $using:throwTerminatingError ) ) -ArgumentList "SourcePathIsNotLocalFailure", $errorMessage, "InvalidData" $errorMessage = "Source path $using:sourcePath has to be local path." ![]() Invoke-Command -ScriptBlock ( :: Create ( $using:throwTerminatingError ) ) -ArgumentList "DestinationPathIsNotUNCFailure", $errorMessage, "InvalidData" $errorMessage = "Destination path $using:destinationPath is not a valid UNC path." $credential = New-Object ( $using:username, $securePassword ) $securePassword = ConvertTo-SecureString $decryptedPassword -AsPlainText -Force $decryptedPassword = Invoke-Command -ScriptBlock ( :: Create ( $using:getDecryptedPassword ) ) -ArgumentList $using:password, $using:certificateThumbprint Write-Debug "Username and password specified." Invoke-Command -ScriptBlock ( :: Create ( $using:throwTerminatingError ) ) -ArgumentList "CertificateThumbprintIsRequired", $errorMessage, "InvalidData" $errorMessage = "Certificate thumbprint has to be specified if credentials are present." # Validate that certificate thumbprint is specified # Generating credential object if password and username are specified # Get script is not implemented cause reusing Script resource's schema does not make sense $password = Invoke-Command -ScriptBlock ( :: Create ( $getEncryptedPassword ) ) -ArgumentList $credential, $certificateThumbprint $cacheLocation = "$env:ProgramData\Microsoft\Windows\PowerShell\Configuration\BuiltinProvCache\MSFT_xFileUpload" ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |