Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- This script is intended to be recieved as an informational bit of code.
- If used, it is with the understanding that the user has a complete understanding of the code and has made any
- necessary changes that are required for their respective environment.
- With this script and any others you find on the internet go through each line and test for yourself before EVER running
- in production.
- #>
- Param(
- [Parameter(Mandatory,HelpMessage = "Location of CSV with list of VM Details that maintenance needs to be performed on")]
- [string]$CSVPath
- )
- Write-Host "Logging Into Azure"
- #login to azure account
- Add-AzureRmAccount
- #Query Azure for All VMs in the current context
- $VMs = Get-AzureRmVM -Status
- $AllVMDetails = [System.Collections.ArrayList]@()
- #Enumerate Through all Azure VMs and Flatten important details of the object
- foreach($VM in $VMs)
- {
- $SubscriptionID = $VM.ID.split("/")[2]
- #Create a new object to flatten data
- $VMDetails = [PSCustomObject]@{
- Name = $VM.Name
- ResourceGroupName = $vm.ResourceGroupName
- Location = $VM.Location
- SubscriptionID = $SubscriptionID
- IsCustomerInitiatedMaintenanceAllowed = $vm.MaintenanceRedeployStatus.IsCustomerInitiatedMaintenanceAllowed
- PreMaintenanceWindowStartTime = $vm.MaintenanceRedeployStatus.PreMaintenanceWindowStartTime
- PreMaintenanceWindowEndTime = $vm.MaintenanceRedeployStatus.PreMaintenanceWindowEndTime
- MaintenanceWindowStartTime = $vm.MaintenanceRedeployStatus.MaintenanceWindowStartTime
- MaintenanceWindowEndTime = $vm.MaintenanceRedeployStatus.MaintenanceWindowEndTime
- LastOperationResultCode = $vm.MaintenanceRedeployStatus.LastOperationResultCode
- LastOperationMessage = $vm.MaintenanceRedeployStatus.LastOperationMessage
- }
- $null = $AllVMDetails.add($VMDetails)
- }
- #Export VM Details of VM to CSVPath
- $AllVMDetails | Export-Csv $CSVPath -NoTypeInformation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement