gpt4 book ai didi

azure - 使用函数包装器的 Invoke-AzResourceAction cmdlet 出现问题

转载 作者:行者123 更新时间:2023-12-03 02:40:45 24 4
gpt4 key购买 nike

我想为 Azure HDInsight 设置证书以进行 Azure DataLake 访问。我正在关注article并使用 Invoke-AzResourceAction cmdlet。

我想知道,为什么代码在没有函数包装器的情况下可以工作,而在使用函数包装器的情况下却失败。我不会更改 azure 订阅。根本没有任何改变,代码只是失败了。

下面的代码工作正常:

### Example Preparation​
# see $HDInsightDefinition.ResourceGroupName​
$resourceGroupName = "PL-Pilot"

# see $HDInsightDefinition.ClusterName​
$clusterName = "plhd01-hdi"

# see $HDInsightDefinition.ServicePrincipalObject.ApplicationId.Guid​
$appId = "280f3a19-ed77-45c"

### get cert details from common keyvault​
# common key vault is available using $HDInsightDefinition.CommonKeyVaultId​
$certStringSecret = Get-AzKeyVaultSecret -Name ("spuucert-{0}" -f $appId) -ResourceId /subscriptions/49e1-a2a6-58ee4a3dd124/resourceGroups/coe-eu-commons/providers/Microsoft.KeyVault/vaults/eu-commons
$certPasswordSecret = Get-AzKeyVaultSecret -Name ("sppwd-{0}" -f $appId) -ResourceId /subscriptions/49e1-a2a6-58ee4a3dd124/resourceGroups/coe-eu-commons/providers/Microsoft.KeyVault/vaults/eu-commons


### update hdi cluster, if cluster already exists and wasn't created immediately before (as in this case, it has the correct identity certificate)​
# => $HDInsightDefinition.ClusterAlreadyExists​
# see https://learn.microsoft.com/en-us/azure/hdinsight/hdinsight-hadoop-use-data-lake-store#refresh-the-hdinsight-certificate-for-data-lake-storage-gen1-access​
Invoke-AzResourceAction `
-ResourceGroupName $resourceGroupName `
-ResourceType 'Microsoft.HDInsight/clusters' `
-ResourceName $clusterName `
-ApiVersion '2015-03-01-preview' `
-Action 'updateclusteridentitycertificate' `
-Parameters @{ ApplicationId = $appId; Certificate = $certStringSecret.SecretValueText; CertificatePassword = $certPasswordSecret.secretvaluetext } `
-Force

但是,当我将上述代码包装在我们框架中的函数中时,代码失败了。我可以确认参数没有问题。 “$HDInsightDefinition”对象将包含传递给上述代码的相同参数值(不带函数包装器)

function Update-XtoHDInsightCertificate {
param
(
[Parameter (ValueFromPipeline = $true, Mandatory = $true)]
$HDInsightDefinition
)

$appid = $HDInsightDefinition.ServicePrincipalObject.ApplicationId.Guid
$certStringSecret = Get-AzKeyVaultSecret -Name ("spuucert-{0}" -f $appid) -ResourceID $HDInsightDefinition.CommonKeyVaultId
$certPasswordSecret = Get-AzKeyVaultSecret -Name ("sppwd-{0}" -f $appid) -ResourceID $HDInsightDefinition.CommonKeyVaultId
$resourceGroupName = $HDInsightDefinition.ResourceGroupName.tostring()
$ClusterName = $HDInsightDefinition.ClusterName.tostring()

# Update the certificate identity of HDInsight Cluster for DataLake Access
Invoke-AzResourceAction `
-ResourceGroupName $resourceGroupName `
-ResourceType 'Microsoft.HDInsight/clusters' `
-ResourceName $ClusterName `
-ApiVersion '2015-03-01-preview' `
-Action 'updateclusteridentitycertificate' `
-Parameters @{ ApplicationId = $appid; Certificate = $certStringSecret.SecretValueText; CertificatePassword = $certPasswordSecret.SecretValueText } `
-Force

write-CoeLog ("Successfully updated certificate for the HDINsight Cluster: {0}" -f $ClusterName)
}

我收到以下错误。我使用“Resolve-AzError”cmdlet 获取了详细信息。

 Resolve-AzError
Breaking changes in the cmdlet 'Resolve-AzError' :
- The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use `Resolve-AzError` instead.


NOTE : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.


HistoryId: 4


Message : {"Message":"An error has occurred."}
StackTrace : at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo capturedException)
at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ErrorResponses.ErrorResponseMessageException
InvocationInfo : {Invoke-AzResourceAction}
Line : Invoke-AzResourceAction `

Position : At C:\Users\manjug\source\repos\eXtollo_April_23_2\coe-df\Continuous Deployment\Deployment\eXtolloInstance\HDInsight_1\HDInsightTools.psm1:17 char:5
+ Invoke-AzResourceAction `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 4



HistoryId: 1


RequestId : d6579b01-bb55-4249-b555-1e0d462a7c6e
Message : Resource group 'non-existent-rg-12345' could not be found.
ServerMessage : ResourceGroupNotFound: Resource group 'non-existent-rg-12345' could not be found. (System.Collections.Generic.List`1[Microsoft.Rest.Azure.CloudError])
ServerResponse : {NotFound}
RequestMessage : {GET https://management.azure.com/subscriptions/3e959272-bef3-49e1-a2a6-58ee4a3dd124/resourceGroups/non-existent-rg-12345/resources?api-version=2019-07-01}
InvocationInfo : {Get-AzResource}
Line : $null = Get-AzResource -ResourceGroupName non-existent-rg-12345 -Name non-existent-resource-32541 -ErrorAction:SilentlyContinue

Position : At C:\Users\manjug\source\repos\eXtollo_April_23_2\coe-df\Continuous Deployment\Framework\CoreDeployment.psm1:6957 char:21
+ ... $null = Get-AzResource -ResourceGroupName non-existent-rg-12345 - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StackTrace : at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo capturedException)
at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
HistoryId : 1


The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.

最佳答案

我能解决这个问题。我对变量进行了类型转换。[字符串]$appid = $HDInsightDefinition.ServicePrincipalObject.ApplicationId.Guid [字符串]$resourceGroupName = $HDInsightDefinition.ResourceGroupName [字符串]$ClusterName = $HDInsightDefinition.ClusterName

关于azure - 使用函数包装器的 Invoke-AzResourceAction cmdlet 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61384699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com