在工作簿中创建哈希 [=10=]
Create Hash Table Within A Workbook
我正在尝试在工作簿中创建散列 table,我已经在 Parrallel 中为自动化帐户创建了它 运行。
我试图用这段代码实现的是输出什么机器在什么时间执行了什么动作。我不是 100% 确定这会在工作流程中起作用,但我一直在尝试尝试一下。希望能帮助您理解我哪里出错了。
if($shouldStop -eq $true -and $scheduleAllowStop -eq $true){
Write-Output "$($resource.Name) -- STOP --"
$Action = 'STOP'
[int]$TimeTaken = (Measure-command {Stop-AzureRmVm -Name $virtualMachine.Name -ResourceGroup $virtualMachine.ResourceGroupName -Force}).TotalMinutes
}
elseif($shouldStart -eq $true -and $scheduleAllowStart -eq $true){
Write-Output "$($resource.Name) -- START --"
$Action = 'START'
[int]$TimeTaken = (Measure-command{Start-AzureRmVm -Name $virtualMachine.Name -ResourceGroup $virtualMachine.ResourceGroupName}).TotalMinutes
}
else{
$Action = 'IGNORE'
$TimeTaken = 0
Write-Output "$($resource.Name) -- IGNORE --"
}
$result = @{
VMName = $virtualMachine.Name
Action = $Action
TotalMinutes = $TimeTaken
}
$output = New-Object -TypeName PSObject -Property $result
$output | Select-Object VMName, Action, TotalMinutes
您可以使用这样的哈希,对于密钥,您最好使用 VM 对象中的 Azure ID,因为它们是唯一的。
$result = @{}
# Declare the # before you loop through VMs
if($shouldStop -eq $true -and $scheduleAllowStop -eq $true){
Write-Output "$($resource.Name) -- STOP --"
$Action = 'STOP'
[int]$TimeTaken = (Measure-command {Stop-AzureRmVm -Name $virtualMachine.Name -ResourceGroup $virtualMachine.ResourceGroupName -Force}).TotalMinutes
}
elseif($shouldStart -eq $true -and $scheduleAllowStart -eq $true){
Write-Output "$($resource.Name) -- START --"
$Action = 'START'
[int]$TimeTaken = (Measure-command{Start-AzureRmVm -Name $virtualMachine.Name -ResourceGroup $virtualMachine.ResourceGroupName}).TotalMinutes
}
else{
$Action = 'IGNORE'
$TimeTaken = 0
Write-Output "$($resource.Name) -- IGNORE --"
}
$resultObj = [PSCustomObject]@{
VMName = $virtualMachine.Name
Action = $Action
TotalMinutes = $TimeTaken
}
$result.Add($virtualMachine.Name, $resultObj)
我正在尝试在工作簿中创建散列 table,我已经在 Parrallel 中为自动化帐户创建了它 运行。
我试图用这段代码实现的是输出什么机器在什么时间执行了什么动作。我不是 100% 确定这会在工作流程中起作用,但我一直在尝试尝试一下。希望能帮助您理解我哪里出错了。
if($shouldStop -eq $true -and $scheduleAllowStop -eq $true){
Write-Output "$($resource.Name) -- STOP --"
$Action = 'STOP'
[int]$TimeTaken = (Measure-command {Stop-AzureRmVm -Name $virtualMachine.Name -ResourceGroup $virtualMachine.ResourceGroupName -Force}).TotalMinutes
}
elseif($shouldStart -eq $true -and $scheduleAllowStart -eq $true){
Write-Output "$($resource.Name) -- START --"
$Action = 'START'
[int]$TimeTaken = (Measure-command{Start-AzureRmVm -Name $virtualMachine.Name -ResourceGroup $virtualMachine.ResourceGroupName}).TotalMinutes
}
else{
$Action = 'IGNORE'
$TimeTaken = 0
Write-Output "$($resource.Name) -- IGNORE --"
}
$result = @{
VMName = $virtualMachine.Name
Action = $Action
TotalMinutes = $TimeTaken
}
$output = New-Object -TypeName PSObject -Property $result
$output | Select-Object VMName, Action, TotalMinutes
您可以使用这样的哈希,对于密钥,您最好使用 VM 对象中的 Azure ID,因为它们是唯一的。
$result = @{}
# Declare the # before you loop through VMs
if($shouldStop -eq $true -and $scheduleAllowStop -eq $true){
Write-Output "$($resource.Name) -- STOP --"
$Action = 'STOP'
[int]$TimeTaken = (Measure-command {Stop-AzureRmVm -Name $virtualMachine.Name -ResourceGroup $virtualMachine.ResourceGroupName -Force}).TotalMinutes
}
elseif($shouldStart -eq $true -and $scheduleAllowStart -eq $true){
Write-Output "$($resource.Name) -- START --"
$Action = 'START'
[int]$TimeTaken = (Measure-command{Start-AzureRmVm -Name $virtualMachine.Name -ResourceGroup $virtualMachine.ResourceGroupName}).TotalMinutes
}
else{
$Action = 'IGNORE'
$TimeTaken = 0
Write-Output "$($resource.Name) -- IGNORE --"
}
$resultObj = [PSCustomObject]@{
VMName = $virtualMachine.Name
Action = $Action
TotalMinutes = $TimeTaken
}
$result.Add($virtualMachine.Name, $resultObj)