【问题标题】:Azure DSC Configuration IssueAzure DSC 配置问题
【发布时间】:2018-11-06 20:59:42
【问题描述】:

基本上,我只是在尝试使用 Azure DSC 访问 VM 详细信息的非常基本的事情。 我做了以下

  • 在我的共享资源下添加了一个新的凭据(包含用户名和密码)和变量(包含订阅 ID) 自动化帐户
  • 已实现以下 DSC 代码以检索 VM 详细信息:我能够在它生成的门户中编译此文件 .MOF 文件也是如此。但是当我尝试将此应用于 门户我收到以下错误:

PowerShell DSC 资源 MSFT_ScriptResource 无法执行 Set-TargetResource 带有错误消息的功能:术语 'Get-AutomationPSCredential' 未被识别为 cmdlet、函数、脚本文件或可运行的程序。检查 名称的拼写,或者如果包含路径,请验证路径 是正确的,然后再试一次

请注意,SetScript 中编写的代码在运行手册中成功执行!!!!!!

    Configuration VMAzureDSCTasks
    {
param
(
    [Parameter()]
    [System.String]
    $NodeName = "rajeshserver",

    [Parameter()]
    [System.String]
    $ResourceGroupName = "rajeshresourcegroup",

    [Parameter()]
    [System.String]
    $VMSize = "Standard_D2s_v3",

    [Parameter()]
    [System.String]
    $CredentialAssetName = "cred"
)

Import-DscResource -ModuleName 'PSDesiredStateConfiguration'        

Node $NodeName
{        
    Script resizevm
    {                 
        SetScript = {

                    # Credentials and Subscription ID declaration
                    $Cred = Get-AutomationPSCredential -Name $using:CredentialAssetName   
                    $null = Add-AzureRmAccount -Credential $Cred -ErrorAction Stop
                $SubId = Get-AutomationVariable -Name 'SubscriptionId'
                $null = Set-AzureRmContext -SubscriptionId $SubId -ErrorAction Stop      

                try {
                $vm = Get-AzureRmVm -ResourceGroupName $using:ResourceGroupName -VMName $using:NodeName -ErrorAction Stop
                } catch {
                throw "Virtual Machine not found!!!!!!" 
                exit
                }

                # Output current VM Size
                $currentVMSize = $vm.HardwareProfile.vmSize

                Write-Verbose -Message "`nFound the specified Virtual Machine: $using:NodeName"
                Write-Verbose -Message "Current size: $using:currentVMSize"

        }
        TestScript = {
         return $false                
        }
        GetScript = {
        }            
    }   
} 

}

【问题讨论】:

    标签: azure azure-virtual-machine dsc


    【解决方案1】:

    Command Get-AutomationPSCredential 适用于 Azure 自动化。

    对于 DSC,使用 Get-Credential 传递凭据。 添加参数

    [Parameter()]
    [pscredential]
    $Credential
    

    并将 Get-AutomationPSCredential 替换为 Get-Credential -Credential $Credential。

    【讨论】:

      猜你喜欢
      • 2020-09-01
      • 2017-09-16
      • 1970-01-01
      • 2020-12-07
      • 2021-05-30
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2017-10-30
      相关资源
      最近更新 更多