我正在尝试使用python代码删除其中的资源组和资源。我已经在powershell中尝试过了,它工作得很好。现在我的组织需要Python。我是python的新手,试着写代码却失败了。
下面是同样的powershell代码。有没有人能帮我弄到python的代码?
提前谢谢。
$rgs = Get-AzureRmResourceGroup;
$rgs=Get-AzureRmResourceGroup -name "TestResourceGroupToClean1";
if(!$rgs)
{
Write-Output "No resource groups in your subscription";
}
else{
Write-Output "You have $($(Get-AzureRmResourceGroup).Count) resource groups in your subscription";
foreach($resourceGroup in $rgs)
{
$name= $resourceGroup.ResourceGroupName;
if($resourceGroup.Tags.ExpiryDate)
{
try{
$ResourceGroupTagDate=[datetime]::ParseExact($resourceGroup.Tags.ExpiryDate,'MM/dd/yyyy',$null)
$count = (Get-AzureRmResource | where { $_.ResourceGroupName -match $name }).Count;
if($ResourceGroupTagDate.Date -lt $today.Date)
{
$subject="Automated Mail from Resource Group Cleaner"
$body="Resource Group $($resourceGroup.ResourceGroupName) including resources has been deleted"
Write-Output "The resource group $name has $count resources. Deleting it...";
Remove-AzureRmResourceGroup -Name $resourceGroup.ResourceGroupName -Force;
Write-Output "The resource group $name and $count resources. Deleted..";
Send-MailMessage -To 'XXXX@XXXXXXXX.com' -Subject $subject -Body $body -UseSsl -Port 587 -SmtpServer 'smtp.office365.com' -From $userid -Credential $creds
}
}
发布于 2018-07-21 04:45:12
https://stackoverflow.com/questions/51441665
复制相似问题