0
問題なく正常に動作していたPowerShellスクリプトを作成しました。夏休みの後、スクリプトを実行するたびに、PSDriveを作成するための資格情報が要求されます。PowerShellが提供された資格情報を使用していません
$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も作成されます。 ここで重要な部分は、ユーザーに何かを促すことではありません。
注記:パスワードを平文でファイルに残しません。これが(私が疑うように)1つのシステムで実行されている場合は、 'Read-Host -AsSecureString | ConvertFrom-SecureString'を実行し、その出力を '$ Destination_Password = output | ConvertTo-SecureString'。私は答えとして使うものの例を掲示します。 – TheIncorrigible1