PowerShell 未使用提供的凭据

PowerShell is not using provided credentials

我创建了一个 PowerShell 脚本,它曾经 运行 没问题。现在暑假过后,每当我 运行 脚本时,它都会要求提供创建 PSDrive 的凭据。

$Source_Path = "\192.168.1.32\Backup_Servers\EAVSRV01\WindowsImageBackup"
$Source_Username = "bcktest"
$Source_Password = "*****" | ConvertTo-SecureString -AsPlainText -Force


$Destination_Path = "\192.168.1.34\Backup_Servers\EAVSRV01\Daily\"
$Destination_Username = "bcktest"
$Destination_Password = "*****" | ConvertTo-SecureString -AsPlainText -Force

#Creates the PSCredential, so we can login to servers, with the required credentials

$Source_Credentials = New-Object System.Management.Automation.PSCredential($Source_Username,$Source_Password)
$Destination_Credentials = New-Object System.Management.Automation.PSCredential($Destination_Username,$Destination_Password)



#Mount the paths as PSDrives, so they're easier to work with

New-PSDrive -Name DestinationDrive -PSProvider FileSystem -Root $Destination_Path -Credential $Destination_Credential
New-PSDrive -Name SourceDrive -PSProvider FileSystem -Root $Source_Path -Credential $Source_Credentials

当我尝试创建 PSDrive "DestinationDrive" 时,它提示输入用户名和密码。如果我按取消,它仍会创建 PSDrive。 当我尝试创建 PSDrive "SourceDrive" 时,它没有提示输入用户名或密码。它还创建了 PSDrive。 这里的重要部分是它不会提示用户进行任何操作。

您的代码中有错字。您为创建目标驱动器而传递的凭据称为 $Destination_Credential,但您之前定义的凭据称为 $Destination_Credentials - 请注意区别!

在 Whosebug 上发帖前请检查您的代码;简单的印刷错误是关闭问题的原因。