Azure Devops Powershell 脚本

问题描述 投票:0回答:1

我是 Azure DevOps 新手。我们有一个管道,管道中的任务之一是将一些配置文件复制到另一台服务器,它看起来像

copy-item -path D:\Config\*.* -Destination '\\server\test\project\files' -r

它正在工作,并且在变量中添加了一个服务帐户(用户名和密码)。对于部署任务(另一个任务),它已添加,并且该帐户的密码最近已更改。我已更新秘密变量中的密码,但 powershell 脚本给出以下内容

copy-item the user name or password is incorrect
。我不确定它抱怨的是哪个帐户,因为脚本中没有设置凭据以及如何解决此错误。

azure-devops azure-powershell
1个回答
0
投票

您可以尝试参考以下PowerShell脚本来修复该问题:

# Converts password strings to be a secure string.
# $(password) is referring the secret pipeline variable.
$password = ConvertTo-SecureString -AsPlainText -Force -String $(password)
$user = $(username)

$credentials = New-Object System.Management.Automation.PSCredential $user,$password

# Map destination server as a network drive.
New-PSDrive -Name "X" -PSProvider FileSystem -Root "\\server\test\project\files" -Credential $credentials

# Copy files to mapped network drive.
Copy-Item -Path "D:\Config\*.*" -Destination X:\
© www.soinside.com 2019 - 2024. All rights reserved.