删除凭据 还可以访问文件服务器,windows - 复制项,用于从本地复制文件以使用凭据删除服务器 - 堆栈内存溢出...

我正在尝试将某些文件和文件夹从本地计算机复制到远程服务器:

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

但出现错误:

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

我尝试使用凭据,但是此命令不允许使用-Credential参数。 我进行了很多搜索,在每个示例中,仅执行Copy-Item $source -destination $destination的命令都非常简单,我想知道为什么在我的工作站中这么难?

创建新的PSDrive

我试图创建一个New-PSDrive但是没有用。

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

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

Copy-Item '.\copy_test.txt' -Destination 'X:\backups'

Remove-PSDrive -Name X

这是错误消息:

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

我的服务器

我的服务器是AWS中的Windows实例。 我拥有正确的权限,因为我可以运行其他命令(如Invoke-Command )来检查远程服务器中的某些服务。

PS> $PSVersionTable.PSVersion

Major Minor Build Revision

----- ----- ----- --------

4 0 -1 -1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值