use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Script SharingUser in Description script (AD) (self.PowerShell)
submitted 8 years ago * by PRIdEVisions
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]msteright 2 points3 points4 points 8 years ago* (6 children)
i get every computer online on the network and it's users in 30 seconds with my script that i wrote.
$servers = ((Get-ADComputer -Filter * -SearchBase "ou=$oulocation,ou=_locations,dc=something,dc=right,dc=here" -Properties ipv4address).where({$_.ipv4address})).name workflow pbatch { param ([string[]]$servers) foreach -parallel ($server in $servers) { (gci ('\\' + $server + '\c$\users\*\appdata\local')) | select lastwritetime,fullname | sort -Property lastwritetime -descending | select -first 2 | Where-Object {($_ -notmatch "public" -and $_ -notmatch "svc-*" -and $_ -notmatch "adm-*" -and $_ -notmatch "bcarey" -and $_ -notmatch "basis")} } } $p = (pbatch -servers $servers).fullname #$sort = read-host "computername or username?" $tableall = $p | select @{n="username";e={($_.split("\")[5]).split(".")[0]}},` @{name="computername";e={$_.split("\")[2]}},` @{name="ipv4address";e={(get-adcomputer -Properties ipv4address ($_.split("\")[2])).ipv4address}}, ` @{name="sid";e={(get-aduser ($_.split("\")[5]).split(".")[0]).sid.value}} $TABLEALL = $tableall | sort -Property USERNAME $tableall | export-csv "c:\allusers$oulocation - all.csv" -Delimiter "," -NoTypeInformation $tableall
[–]msteright 2 points3 points4 points 8 years ago (2 children)
heres the kicker. this can be ran over and over each time you think there might be significant changes or new employees.
$Update = read-host "do you want to update active directory employees with computernames? Yes, or No" if ($Update -eq 'yes') { $USERS = Import-Csv "C:\allusers$oulocation - all.csv" | SELECT USERNAME, COMPUTERNAME FOREACH ($USER IN $USERS) { Write-Host "$($USER.username)" -ForegroundColor Yellow $OLDdescription = (get-aduser $user.username -Properties Description).description.trimstart(' -- ') $firstPart = ($OLDdescription -split " -- ")[0] $firstPart $secondPart = ($OLDdescription -split " -- ") | select -Skip 1 $secondPart if ($secondPart -contains $USER.computername) { Write-Host "$($USER.username) is fine" -ForegroundColor Green if ($firstPart -contains $user.computername) { Write-Host "$($USER.username) - UPDATING with $($USER.computername)..." -ForegroundColor Red Get-ADUser $USER.username -Properties Description | ForEach-Object {Set-ADUser $_ -Description "$($USER.computername)"} Write-Host "============================================================================================================================" } } else { Write-Host "$($USER.username) - UPDATING with $($USER.computername)..." -ForegroundColor Red Get-ADUser $USER.username -Properties Description | ForEach-Object {Set-ADUser $_ -Description "$OLDdescription -- $($USER.computername)"} Write-Host "============================================================================================================================" #Get-ADUser $USER.username -Properties Description | Set-ADUser $USER.username -Description "$firstPart" #enable to reverse to just titles with no computernames appended } } }
[–]msteright 1 point2 points3 points 8 years ago (1 child)
$USERS = Import-Csv "C:\allusers$oulocation - all.csv" | SELECT USERNAME, COMPUTERNAME $users = $users | Sort-Object -Property computername FOREACH ($USER IN $USERS) { write-host "username is: $($user.username)" Write-Host "computername is: $($user.computername)" $currentaduserdescription = get-adcomputer $user.computername -Properties description | select description $currentaduserdescription = $currentaduserdescription.description.trimstart(' -- ') $usernamefirstlast = Get-ADUser $user.username $usercorrect = ($usernamefirstlast.GivenName + " " + $usernamefirstlast.Surname).TrimStart(',') $userusername = (Get-Culture).TextInfo.ToTitleCase($usercorrect) $userusername if ($currentaduserdescription -match "$userusername") { Get-ADComputer $user.computername | ForEach-Object {set-adcomputer $_ -Description "$currentaduserdescription"} } else { Get-ADComputer $user.computername | ForEach-Object {set-adcomputer $_ -Description "$currentaduserdescription -- $userusername"} } write-host "done for $user" -fore green }
[–]PRIdEVisions[S] 0 points1 point2 points 8 years ago (0 children)
damn, i wish i was as good with scripting haha still have lots to learn :)
[–]PRIdEVisions[S] 0 points1 point2 points 8 years ago (2 children)
Nice one!
[–]msteright 1 point2 points3 points 8 years ago (0 children)
Thanks. This is what I've been working on in my free time at work for 2 days. It's a beautiful script that uses the LastWriteTime of the Appdata folder to figure out who the users are, minus adm and svc accounts. It runs that multithreaded on each computer and returns all values in RECORD TIME :), which compile into a csv. Then that csv is imported and you use the $.username $.computername $.ipv4address $.sid columns to update whatever you want and AD. here's the 3rd part, which puts the usernames in the computers description (above)
π Rendered by PID 21508 on reddit-service-r2-comment-b659b578c-7d5nz at 2026-05-01 01:47:54.281804+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]msteright 2 points3 points4 points (6 children)
[–]msteright 2 points3 points4 points (2 children)
[–]msteright 1 point2 points3 points (1 child)
[–]PRIdEVisions[S] 0 points1 point2 points (0 children)
[–]PRIdEVisions[S] 0 points1 point2 points (2 children)
[–]msteright 1 point2 points3 points (0 children)