I want to create a PowerShell script to copy the Templates folder from a remote computer to a local computer:
Ask the administrator to enter the name of the remote PC
$RemotePCName = Read-Host “Please enter the name of the remote PC”
Ask the administrator to enter their credentials
$Credential = Get-Credential -Message “Enter your administrator credentials to connect to remote PC $RemotePCName”
$IdenUser = Read-Host “Please enter user account ID”
#Templates folder path:
$path_outlook_templates = “C:Users$IdenUserAppDataRoamingMicrosoftTemplates”
Local PC variable declaration:
$local_pc_path = “C:Usersba89260Documentstest”
$LocalPCName = $env:COMPUTERNAME
Creating a session between the remote PC and the local PC
Write-Host “Creating a session between the remote PC $RemotePCName and the local PC $LocalPCName:”
$Session = New-PSSession -ComputerName $RemotePCName -Credential $Credential
if ($Session -eq $null) {
[System.Windows.Forms.MessageBox]::Show(“The connection between computer $RemotePCName and computer $LocalPCName could not be established.”, “Session error”, “OK”, “Error” )
exit
}
Write-Host “Success! Next step”
Copy Outlook Templates folder
Write-Host “Copying the Templates folder…”
Copy-Item -Path $outlook_templates_path -Destination $local_pc_path -FromSession $Session -Recurse -Force
Write-Host “Success! Next step”#
Displaying a Windows window
#[Opening Windows message box]::Show(“Message to display in the window”, “Title in the window”, “button”, “icon in the message”)
[System.Windows.Forms.MessageBox]::Show(“Copying data from $RemotePCName to $LocalPCName is complete.”, “Done”, “OK”, “Information”)
The script does what I ask of it EXCEPT that the console returns me the ‘Stream’ error in a loop :
Copy-Item: Could not find a parameter matching the name “Stream”.
To the character Line 31: 1
- Copy-Item -Path $outlook_templates_path -Destination $pc_path …
-
+ CategoryInfo: InvalidArgument: (:) [Get-Item], ParameterBindingException + FullyQualifiedErrorId: NamedParameterNotFound,Microsoft.PowerShell.Commands.GetItemCommand
I tested with -LiteralPath or -Path but the result is the same. And I want to point out that I was able to copy this folder from the local computer to the remote computer…and I didn’t get any errors.
Can you please help me find a solution? Thanks for your help
user24950367 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.