Get SamAccountname from the list of Displayname

Import-Module activedirectory
$displayname = @()
$names = get-content “c:\user.txt”
foreach ($name in $names) {

$displaynamedetails = Get-ADUser -filter { DisplayName -eq $name } -server “Domain name “| Select name,samAccountName

$displayname += $displaynamedetails


$displayname | Export-Csv “C:\Samaccountname.csv”

Powershell script to find old AD computers by last login time

import-module activedirectory
$logdate = Get-Date -format yyyyMMdd
$logfile = “c:\scripts\logs\ExpiredComputers – “+$logdate+”.csv”
$mail = “”
$smtpserver = “”
$emailFrom = “”
$domain = “xybioncorp.local”
$emailTo = “$mail”
$subject = “Old computers in Active Directory”
$DaysInactive = 180
$time = (Get-Date).Adddays(-($DaysInactive))
$body =
“Please find the inactive computers file. Please review


# Change this line to the specific OU that you want to search
$searchOU = “DC=xybioncorp, DC=local”

# Get all AD computers with LastLogon less than our time
Get-ADComputer -SearchBase $searchOU -Filter {LastLogon -lt $time -and enabled -eq $true} -Properties LastLogon, description,Operatingsystem|

# Output hostname and LastLogon into CSV
select-object Name,DistinguishedName, description,Operatingsystem,enabled,@{Name=”Stamp”; Expression={[DateTime]::FromFileTime($_.LastLogon)}} | export-csv $logfile -notypeinformation

Send-MailMessage -To $emailTo -From $emailFrom -Subject $subject -Body $body -Attachments $logfile -SmtpServer $smtpserver

Step-By-Step: Migrating The Active Directory Certificate Service From Windows Server 2008 R2 to 2019

AD Sites & Services

Explained: Active Directory Authoritative Restore

Dumping Domain Password Hashes

How to Restrict DNS Zone Scavenging When Hosting Multiple Zones on Multiple Servers

Finding Orphaned Domain Controllers in Active Directory Sites and Services

RODC Technical Reference Topics

User and Setting the ManagedBy Computer Attribute

%d bloggers like this: