In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Recently received a demand, want to take a look at the Azure virtual machine creation records, detailed understanding of the recent cloud what new resources, this is actually a relatively normal demand, as the cloud is more and more widely used, many enterprises are no longer satisfied with the simple use of the cloud, but more focused on how to make good use of the cloud, a more core point is that more and more enterprises begin to pay attention to the cloud cost problem Therefore, the rationality of the use of resources is more and more a focus of enterprises.
To return to the topic, then how to achieve this requirement in Azure? in fact, the creation record of VM can be found in the deployment record of the resource group, but the information collected in this way is very fragmented, and it is impossible for us to check and sort out this information one by one, so what is the good way?
In fact, we can solve this problem directly through Azure's PowerShell. We only need to write a simple script. First, run the following command to get all the log of Azure in the past three months.
$logs = Get-AzureRmLog-ResourceProvider Microsoft.Compute-StartTime (Get-Date). AddDays (- 90)-Maxrecord 100000
Foreach ($log in $logs) {if (($log.OperationName.Value-eq 'Microsoft.Compute/virtualMachines/write')-and ($log.SubStatus.Value-eq' Created')) {Write-Output "$($log.caller) created vm $($log.Id.split (" / ") [8]) at $($log.EventTimestamp) in ResourceGroup $($log.ResourceGroupName)"}}
So you can see the record created by VM!
What if you want to aggregate this information into Excel? You can use the following code!
[pscustomobject []] $VMObjects = $nullforeach ($log in $logs) {if (($log.OperationName.Value-eq 'Microsoft.Compute/virtualMachines/write')-and ($log.SubStatus.Value-eq' Created')) {Write-Output "$($log.caller) created vm $($log.Id.split (" / ") [8]) at $($log.EventTimestamp) in ResourceGroup $($log.ResourceGroupName)" $VMObject = New- Object-TypeName psobject $VMObject | Add-Member-MemberType NoteProperty-Name SubscriptionName-Value $SubscriptionName $VMObject | Add-Member-MemberType NoteProperty-Name SubscriptionID-Value $SubscriptionID $VMObject | Add-Member-MemberType NoteProperty-Name ResourceGroup-Value $log.ResourceGroupName $VMObject | Add-Member-MemberType NoteProperty-Name VMName-Value $log.Id.split ("/") [8] $VMObject | Add-Member-MemberType NoteProperty-Name Time-Value $log.EventTimestamp $VMObjects + = $VMObject}} $OutputPath= "C:\ vm.csv" $VMObjects | Export-Csv-NoTypeInformation-LiteralPath $OutputPath
Finally, this method can only collect logs within 90 days, because the longest log open to users on the Azure platform is 90 days.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.