ナビゲーションをスキップする

Azure Data Lake Analytics find inactive accounts with PowerShell

最終更新: 2018/05/05
GitHub で編集
Set-StrictMode -Version 2
$ErrorActionPreference = "Stop"

$WarningPreference = 'SilentlyContinue'

Class AccountInfo
{
    [String] $AnalyticsAccount
    [DateTime] $AnalyticsAccountCreatedOn
    [Int] $AnalyticsAccountAgeInDays
    [NUllable[DateTime]] $LastJobSubmitted
    [String] $LastJobSubmittedBy
    [NUllable[Double]] $LastJobSubmittedDaysAgo

}

$subid = "ace74b35-b0de-428b-a1d9-55459d7a6e30"

#Login-AzureRmAccount -Subscription $subid

# get all the accounts in the subscription
$adla_accounts = Get-AdlAnalyticsAccount 


# For testing against a specific acount
#$sandbox_account= Get-AdlAnalyticsAccount -Name "sandbox"
#$adla_accounts = @($sandbox_account)



function Get-ADLUsageInfo( $adla_account )
{
    $now = Get-Date
    $now_utc = $now.ToUniversalTime()

    $info = New-Object AccountInfo

    $info.AnalyticsAccount = $adla_account.Name
    $info.AnalyticsAccountCreatedOn = $adla_account.CreationTime
    $info.AnalyticsAccountAgeInDays = ($now_utc - $adla_account.CreationTime).TotalDays


    $job = Get-AdlJob -Account $adla_account.Name -Top 1


    if ($job -ne $null)
    {
        $time_delta = $now_utc - $job.SubmitTime.DateTime

        $info.LastJobSubmitted = $job.SubmitTime.DateTime
        $info.LastJobSubmittedBy = $job.Submitter
        $info.LastJobSubmittedDaysAgo = $time_delta.TotalDays

    }
    else
    {
        $info.LastJobSubmitted = $null
        $info.LastJobSubmittedBy = $null
        $info.LastJobSubmittedDaysAgo = $null
    }

    return $info
}


$infos = New-Object "System.Collections.Generic.List[AccountInfo]"
foreach ($adla_account in $adla_accounts)
{
    Write-Host "Getting information for" $adla_account.Name
    $info = Get-ADLUsageInfo $adla_account

    #Write-Output $info
    $infos.Add($info)
}



$infos