您好,登錄后才能下訂單哦!
本文以azure為例,為大家分析用powershell腳本查看用戶的操作記錄的方法。閱讀完整文相信大家對(duì)powershell腳本的使用方法有了一定的認(rèn)識(shí)。
下邊來看下代碼的內(nèi)容,其實(shí)是很簡(jiǎn)單的
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 }
我們來嘗試著運(yùn)行一下腳本Get-AzureUserActionLog.ps1 -User "xxx@xxx.partner.onmschina.cn", -User的作用是我們可以根據(jù)這個(gè)參數(shù)篩選出來特定的用戶
腳本執(zhí)行完成后,可以在桌面上看到一個(gè)csv文件,里邊會(huì)記錄查詢出來log
提醒一點(diǎn),因?yàn)锳zure后臺(tái)的限制,這只能查詢到最近90天之內(nèi)的log。
看完這篇文章,你們學(xué)會(huì)用powershell腳本查看用戶的操作記錄了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。