這篇文章給大家分享的是有關怎么查詢Azure用戶操作記錄的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
下邊來看下代碼的內容,其實是很簡單的
param (
[parameter(Mandatory = $false)]
[Int]$MaxRecords = 100000,
[parameter(Mandatory = $true)]
[string]$User
)
function Write-DateTimeMessage {
param (
[parameter(Mandatory = $false)]
[switch]$Warning,
[parameter(Mandatory = $true)]
[string]$Message,
[parameter(Mandatory = $false)]
[string]$ForegroundColor
)
if ($Warning) {
Write-Warning ($(Get-Date -UFormat '%Y/%m/%d %H:%M:%S') + " * " + $Message)
}
else {
if ($ForegroundColor) {
Write-Host ($(Get-Date -UFormat '%Y/%m/%d %H:%M:%S') + " * " + $Message) -ForegroundColor $ForegroundColor
}
else {
Write-Host ($(Get-Date -UFormat '%Y/%m/%d %H:%M:%S') + " * " + $Message)
}
}
}
[pscustomobject[]]$UserObjects = $null
$Subscriptions = Get-AzureRmSubscription
foreach ($subscription in $Subscriptions) {
" "
"Querying Subscription:"
$SubscriptionID = $Subscription.Id
$SubscriptionName = $Subscription.Name
Select-AzureRmSubscription -SubscriptionId $SubscriptionID -InformationAction SilentlyContinue
Write-DateTimeMessage -Message "Retrieving logs, please wait..."
$logs = Get-AzureRmLog -ResourceProvider Microsoft.Compute -StartTime (Get-Date).AddDays(-90) -Maxrecord $MaxRecords
foreach ($log in $logs) {
if ($log.caller -eq $User) {
$UserObject = New-Object -TypeName psobject
$UserObject | Add-Member -MemberType NoteProperty -Name SubscriptionName -Value $SubscriptionName
$UserObject | Add-Member -MemberType NoteProperty -Name SubscriptionID -Value $SubscriptionID
$UserObject | Add-Member -MemberType NoteProperty -Name ResourceGroup -Value $log.ResourceGroupName
$UserObject | Add-Member -MemberType NoteProperty -Name Caller -Value $log.caller
$UserObject | Add-Member -MemberType NoteProperty -Name Operation -Value $log.OperationName.Value
$UserObject | Add-Member -MemberType NoteProperty -Name ResourceId -Value $log.ResourceId
$UserObject | Add-Member -MemberType NoteProperty -Name Time -Value $log.EventTimestamp
$UserObjects += $UserObject
}
}
}
$OutputPath = Join-Path -Path ([Environment]::GetFolderPath("Desktop")) -ChildPath ("AzureUserAction-" + $(Get-Date -Format "yyyyMMdd-HHmmss") + ".csv")
if ($null -ne $UserObjects) {
$UserObjects | Export-Csv -NoTypeInformation -LiteralPath $OutputPath
Write-DateTimeMessage -Message "Please check $OutputPath" -Warning
}
else {
Write-DateTimeMessage "Didn't get information, please check" -warning
}我們來嘗試著運行一下腳本Get-AzureUserActionLog.ps1 -User "xxx@xxx.partner.onmschina.cn", -User的作用是我們可以根據這個參數篩選出來特定的用戶

腳本執行完成后,可以在桌面上看到一個csv文件,里邊會記錄查詢出來log

最后,還是要提醒一點,因為Azure后臺的限制,這只能查詢到最近90天之內的log
感謝各位的閱讀!關于“怎么查詢Azure用戶操作記錄”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。