Copiar item para copiar arquivos do local para remover o servidor usando credenciais

Estou tentando copiar alguns arquivos e pastas da minha máquina local para um servidor remoto:

Copy-Item .\copy_test.txt -destination "\\serverip\c$\backups\"

mas estou recebendo um erro:

Copy-Item : Logon failure: unknown user name or bad password.
At line:1 char:10
+ Copy-Item <<<<  .\copy_test.txt -destination "\\serverip\c$\backups\" -verbose
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand

Eu estava tentando usar credenciais, mas este comando não permite-Credential argumento. Eu estava pesquisando bastante e, em todos os exemplos, o comando é bem fácil, basta executar oCopy-Item $source -destination $destination e eu me pergunto por que é tão difícil na minha estação de trabalho.

Criando um novo PSDrive

Eu tentei criar umNew-PSDrive mas não funcionou.

$creds = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username, $password

New-PSDrive -Name X -PSProvider FileSystem -Root '\\$serverip\c

É a mensagem de erro:

PS C:\Users\Administrator\Desktop> .\copyfiles.ps1
New-PSDrive : The network path was not found
At C:\Users\Administrator\Desktop\copyfiles.ps1:11 char:1
+ New-PSDrive -Name X -PSProvider FileSystem -Root '\\$serverip\c$' -Credential $c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (X:PSDriveInfo) [New-PSDrive], Win32Exception
    + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveC

Copy-Item : Cannot find drive. A drive with the name 'X' does not exist.
At C:\Users\Administrator\Desktop\copyfiles.ps1:12 char:1
+ Copy-Item '.\copy_test.txt' -Destination 'X:\backups'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (X:String) [Copy-Item], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.CopyItemCommand

Remove-PSDrive : Cannot find drive. A drive with the name 'X' does not exist.
At C:\Users\Administrator\Desktop\copyfiles.ps1:13 char:1
+ Remove-PSDrive -Name X
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (X:String) [Remove-PSDrive], DriveNotFoundExcepti
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.RemovePSDriveCommand
Meus servidores

Meu servidor são instâncias do Windows na AWS. Eu tenho a permissão correta porque sou capaz de executar outro comando comoInvoke-Command para inspecionar alguns serviços no servidor remoto.

PS> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1
-Credential $creds -Persist Copy-Item '.\copy_test.txt' -Destination 'X:\backups' Remove-PSDrive -Name X

É a mensagem de erro:

PS C:\Users\Administrator\Desktop> .\copyfiles.ps1
New-PSDrive : The network path was not found
At C:\Users\Administrator\Desktop\copyfiles.ps1:11 char:1
+ New-PSDrive -Name X -PSProvider FileSystem -Root '\\$serverip\c$' -Credential $c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (X:PSDriveInfo) [New-PSDrive], Win32Exception
    + FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveC

Copy-Item : Cannot find drive. A drive with the name 'X' does not exist.
At C:\Users\Administrator\Desktop\copyfiles.ps1:12 char:1
+ Copy-Item '.\copy_test.txt' -Destination 'X:\backups'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (X:String) [Copy-Item], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.CopyItemCommand

Remove-PSDrive : Cannot find drive. A drive with the name 'X' does not exist.
At C:\Users\Administrator\Desktop\copyfiles.ps1:13 char:1
+ Remove-PSDrive -Name X
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (X:String) [Remove-PSDrive], DriveNotFoundExcepti
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.RemovePSDriveCommand
Meus servidores

Meu servidor são instâncias do Windows na AWS. Eu tenho a permissão correta porque sou capaz de executar outro comando comoInvoke-Command para inspecionar alguns serviços no servidor remoto.

PS> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1

questionAnswers(2)

yourAnswerToTheQuestion