新进化论

道生一,一生二,二生三,三生万物。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
function Get-ADUserLastLogon($userName)
{
$dcs = Get-ADDomainController -Filter {Name -like "*"}
$time = 0
foreach($dc in $dcs)
{
$hostname = $dc.HostName
$user = Get-ADUser $userName -Server $hostname | Get-ADObject -Properties lastLogon
if($user.LastLogon -gt $time)
{
$time = $user.LastLogon
}
}
$dt = [DateTime]::FromFileTime($time)

Write-Host $username.samaccountname "last logged on at:" $dt 
}

$Groups = Get-ADGroup -Filter {Name -like "fi*"}

$groupmembers = @()
ForEach ($Group in $Groups) {
    $groupmembers += (Get-ADGroupMember -Identity "$($Group.Name)"  -Recursive)
}
$groupmembers = $groupmembers|select  -Unique

foreach($account in $groupmembers)
{

Get-ADUserLastLogon -UserName $account

}

 

posted on 2019-12-02 09:41  岌岌可危  阅读(264)  评论(0编辑  收藏  举报