top of page

PowerShell - Get all AD Users Account creation and changed dates

  • Writer: Jon Boyette
    Jon Boyette
  • Jan 10, 2022
  • 1 min read

Save as a .ps1 and run, outputs all Users to c:\temp\AllADUsersCreationInfo.txt with account creation and changed info, includes if account is expired


Function Get-UserProcess {

[CmdletBinding()]

param (

[Parameter(Position=0, Mandatory = $true, HelpMessage="Provide server names", ValueFromPipeline = $true)] $Computername,

[Parameter(Position=1, Mandatory = $false, HelpMessage="Provide username", ValueFromPipeline = $false)] $UserName = $env:USERNAME

)

$Array = @()

Foreach ($Comp in $Computername) {

$Comp = $Comp.Trim()

Write-Verbose "Processing $Comp"

Try{

$Procs = $null

$Procs = Invoke-Command $Comp -ErrorAction Stop -ScriptBlock{param($Username) Get-Process -IncludeUserName | Where-Object {$_.username -match $Username}} -ArgumentList $Username

If ($Procs) {

Foreach ($P in $Procs) {

$Object = $Mem = $CPU = $null

$Mem = [math]::Round($P.ws / 1mb,1)

$CPU = [math]::Round($P.CPU, 1)

$Object = New-Object PSObject -Property ([ordered]@{

"ServerName" = $Comp

"UserName" = $P.username

"ProcessName" = $P.processname

"CPU" = $CPU

"Memory(MB)" = $Mem

})

$Array += $Object

}

}

Else {

Write-Verbose "No process found for $Username on $Comp"

}

}

Catch{

Write-Verbose "Failed to query $Comp"

Continue

}

}

If ($Array) {

Return $Array

} Export-Csv c:\temp\AllADUsersCreationInfo.txt -NoTypeInformation

}



 
 
 

Recent Posts

See All
PowerShell - List All Domain SPNs

Save as same List_ALL_SPNs.ps1 or similar, this LDap calls the Domain for all Service Principal names and accounts related #Build LDAP...

 
 
 
PowerShell - Start-Monitoring

This is a great script used to Monitor and Email if a server is up or down, once ran, and smtp and from address is set, then run:...

 
 
 

Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Boyette Technical Services. Proudly created with Wix.com

bottom of page