Invoke-AzureRmVMRunCommand参数突然传递失败

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

Context:运行Azure自动化帐户解决方案,其中调用方PS脚本执行另一个PS脚本(在VM上执行),并通过'Invoke-AzureRmVMRunCommand'传递参数。

故事:我运行了一个PowerShell(调用者)脚本,该脚本在远程Azure Win VM上执行了另一个(称为)PowerShell脚本。该流每天通过自动化帐户计划运行,但是由于两天前从调用者传递到被调用脚本的参数不再起作用,因此突然停止工作。我目前责怪MSFT Azure人员破坏了我的PRD解决方案。

这里是传递参数的调用者PS脚本代码:

$hshParams = @{
    strSAName         = $hshParameters.strStagingSA
    strSAAccessKey    = $strSAAccessKey
    strFileShare      = '"' + $strFileShare + '"'
    strCopyObjects    = $hshParameters.strCopyObjects
    strSrcDriveLetter = $strSrcDriveLetter
    strDstDriveLetter = $strDstDriveLetter
}

这里是VM运行的PS脚本的调用:

Invoke-AzureRmVMRunCommand -ResourceGroupName $objVM.ResourceGroupName -Name $objVM.Name `
    -CommandId 'RunPowerShellScript' -ScriptPath $strRemoteScriptFileNameTmp -Parameter $hshParams

这里是在VM运行的PS脚本侧的参数接收代码:

# Parameters
Param (
    [string] $strCopyObjects = $null,
    [string] $strSAAccessKey = $null,
    [string] $strFileShare = $null,
    [string] $strSAName = $null,
    [string] $strDstDriveLetter = $null,
    [string] $strSrcDriveLetter = $null
)

直到两天前,这六个字符串值均已正确填充,并根据哈希表'$ hshParams'中的参数设置进行了填充:

$strSAAccessKey = 92LO1Q4tuyeiqxxx
$strFileShare = 129xxxa1.file.core.windows.net\solutionfiles
$strSAName = 12xsa1
$strDstDriveLetter = D
$strSrcDriveLetter = Z
$strCopyObjects = AutoTopUp\Application\Live

问题:现在,我看到五个字符串值突然不再填充而其中一个变成了垃圾,这就是今天的样子:

$strSAAccessKey = []
$strFileShare = []
$strSAName = []
$strDstDriveLetter = []
$strSrcDriveLetter = []
$strCopyObjects = AutoTopUp\Application\Live" -strSAAccessKey 92LO1Q4tuyeiqxxx -strFileShare 129xxxa1.file.core.windows.net\solutionfiles -strSAName 12xsa1 -strDstDriveLetter D -strSrcDriveLetter Z

未解决该解决方案,它只是按计划运行。 VM运行脚本上的$ Args.Count返回'2'。

我的问题:有人对此新行为有解释吗?令人沮丧的是,我没有设法以不同的方式来安排参数传递,因为它有点不清楚接收哈希表值的正确方式。 “ Invoke-AzureRmVMRunCommand”的MSFT帮助页面(当然)在这里没有帮助,我也没有在传递给SO或Google的参数上找到任何其他明确的方法...

azure powershell parameter-passing remote-access azure-automation
1个回答
0
投票

this MSDN线程中提出了相关问题;只是分享这些内容是为了让可能面临类似问题的广大受众受益。

© www.soinside.com 2019 - 2024. All rights reserved.