基本上我只是尝试使用Azure DSC访问VM详细信息的基本功能。 我做了以下
PowerShell DSC资源 MSFT_ScriptResource无法执行Set-TargetResource 带错误消息的功能:术语 “Get-AutomationPSCredential”未被识别为a的名称 cmdlet,函数,脚本文件或可操作程序。检查 拼写名称,或者如果包含路径,请验证路径 是正确的,然后再试一次
请注意,在RunScript中编写的代码在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 = {
}
}
}
}
答案 0 :(得分:0)
命令Get-AutomationPSCredential在Azure自动化中工作。
对于DSC,请使用Get-Credential传递凭据。 添加参数
[Parameter()]
[pscredential]
$Credential
并将Get-AutomationPSCredential替换为Get-Credential -Credential $ Credential。