[英]Azure DSC Configuration Issue
Basically I am just trying a very basic thing of accessing the VM details using Azure DSC. 基本上,我只是尝试使用Azure DSC访问VM详细信息的非常基本的事情。 I have done the following
我做了以下
PowerShell DSC resource MSFT_ScriptResource failed to execute Set-TargetResource functionality with error message: The term 'Get-AutomationPSCredential' is not recognized as the name of a cmdlet, function, script file, or operable program. PowerShell DSC资源MSFT_ScriptResource无法执行Set-TargetResource功能,并显示错误消息:术语“ Get-AutomationPSCredential”未被识别为cmdlet,函数,脚本文件或可运行程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again
检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试
Please note that the code written inside the SetScript executes successfully in a runbook!!!!!! 请注意,在SetScript中编写的代码可以在Runbook中成功执行!
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 = {
}
}
}
} }
Command Get-AutomationPSCredential works in Azure Automation. 命令Get-AutomationPSCredential在Azure自动化中运行。
For DSC, pass credentials using Get-Credential. 对于DSC,请使用Get-Credential传递凭据。 Add parameter
添加参数
[Parameter()]
[pscredential]
$Credential
And replace Get-AutomationPSCredential with Get-Credential -Credential $Credential. 并将Get-AutomationPSCredential替换为Get-Credential -Credential $ Credential。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.