I have put together a routing that does the following
- foreach ($AzureAccount in (Get-AzureAccount).ID) {Remove-AzureAccount $AzureAccount -Force} - This removes any Subscription session to my machine it works
2.$subscription = Get-Content “C:\subscriptionsList.txt” - Reads a txt file for the name of the subscription to connect to. The file has a list of 4 Azure subscription and the read routine works.
3.foreach ($Line In $Subscription)
{
$Fields = $Line -Split " "
$subName = $Fields[3]
write-host "Subscription Name is: "$subName
Write-Host “”
}
The routine above simply splits the line and defines the separator which is a tab as each line has other data and it declares the $subscription variable. Finally, displays the list of subscriptions the read routine pulls from the text file
-
Add-AzureAccount - This line pops up a screen which requires the login ID and password - It also does come up and works.
-
Get-AzureService | Select-Object @{“Label”=“ServiceName”;Expression={$.Label}} | ForEach-Object {Remove-AzureDeployment -ServiceName $.ServiceName -Slot Production -DeleteVHD -Force -ErrorVariable a -ErrorAction silentlycontinue
Remove-AzureService $_.ServiceName -Force
} - This cmdlet basically gets a list of services then pipes to the next routine which deletes them and it works -
Remove-AzureVNetconfig - Finally this cmdlet removed all Vitual Networs in the subscription it also works
THE QUESTION:
My code does not loop through and does the whole script for the next subscription as read from the text file so that bit is not working and is what I need help with. Kindly assist
________________THE Full SCRIPT ___________________
foreach ($AzureAccount in (Get-AzureAccount).ID) {Remove-AzureAccount $AzureAccount -Force}
$subscription = Get-Content “C:\subscriptionsList.txt”
foreach ($Line In $Subscription)
{
$Fields = $Line -Split " "
$subName = $Fields[3]
write-host "Subscription Name is: "$subName
Write-Host “”
}
Add-AzureAccount
Get-AzureService | Select-Object @{“Label”=“ServiceName”;Expression={$.Label}} | ForEach-Object {Remove-AzureDeployment -ServiceName $.ServiceName -Slot Production -DeleteVHD -Force -ErrorVariable a -ErrorAction silentlycontinue
Remove-AzureService $_.ServiceName -Force
}
Remove-AzureVNetconfig