Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Exporting from Active Directory (SBS) list of active and disabled domain users to a txt file

$
0
0

Hi everyone,

As you'll see I'm pretty much "fresh" in PowerShell.
I've found this Ed Wilson's script named "FindDisabledUserAccounts.ps1" and it works perfectly on my Small Busyness Server with PowerShell 2.0.
It even lists all active domain users in green and disabled users in red colour, which makes it very easy to navigate through results.
My problem is that I can't find a way to export those results to txt file for a report purposes.
I added that last line "Out-File D:\SBS_users.txt" to Ed's script and it saves txt file right on the spot with no problem whatsoever.
Problem is that txt file in question is always EMPTY, there is NO single line in it?
I can't export results directly to csv format 'cause there is no MS Office Excel instalation on SBS.
Please help.
Thanks in advance.

Script - FindDisabledUserAccounts.ps1:

$filter = "(&(objectClass=user)(objectCategory=person))"
$users = ([adsiSearcher]$Filter).findall()

 foreach($suser in $users)
  {
   "Testing $($suser.properties.item(""distinguishedname""))"
   $user = [adsi]"LDAP://$($suser.properties.item(""distinguishedname""))"
 
   $uac=$user.psbase.invokeget("useraccountcontrol")
     if($uac -band 0x2)
       { write-host -foregroundcolor red "`t account is disabled" }
     ELSE
       { write-host -foregroundcolor green "`t account is not disabled" }
  } #foreach
Out-File D:\SBS_users.txt


Viewing all articles
Browse latest Browse all 6937

Trending Articles