-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Hi Paul,
Thanks for sharing your brilliant idea on the schedule tag. I'm using it in our Azure Sub to saving cost. However, I think you script was developed when the tags property of AzureRMReource is still hashtable array. At the moment, the tags property is just hashtable. Therefore, a few tweaks need to be made to your scripts:
function ContainsSchedule
{
param
(
[Parameter(Mandatory=$false)]
[System.Collections.Hashtable]$tags
)
if ($tags -eq $null)
{
return $false
}
foreach ($key in $tags.Keys)
{
if ($key -eq "schedule")
{
return $true
}
}
return $false
}
function GetSchedule
{
param
(
[Parameter(Mandatory=$false)]
[System.Collections.Hashtable]$tags
)
if ($tags -eq $null)
{
return $null
}
foreach ($key in $tags.Keys)
{
if ($key -eq "schedule")
{
return $tags[$key]
}
}
}
-------------->
$resource = Get-AzureRmResource -Name $vmName -ResourceType "Microsoft.Compute/virtualmachines"
foreach ($key in $resource.Tags.Keys)
{
if ($key -ne "schedule")
{
$tags.Add($key, $resource.Tags[$key])
}
}
$scheduleJson = $_[1]
$tags +=@{"schedule"=$scheduleJson}
<----------------
I'm happy to create a PR if you make me contributor.
Thanks again for sharing your brilliant script and idea!
Jason
Metadata
Metadata
Assignees
Labels
No labels