tag:blogger.com,1999:blog-4934393933440874074.post1537366804134914932..comments2022-01-27T23:27:00.354-06:00Comments on Up the Down Codebase: Getting Active Directory account information using PowerShellJeff Olsonhttp://www.blogger.com/profile/10359981784036083692noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-4934393933440874074.post-53717515538823549102015-12-15T15:17:59.528-06:002015-12-15T15:17:59.528-06:00This would be a pretty simple change to the script...This would be a pretty simple change to the script. Just move the column headings above the loop and print the fields on a single line. Something like this:<br /><br />Add-Type -AssemblyName System.DirectoryServices.AccountManagement<br />$users = get-content 'users.txt'<br />$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain<br /><br />"Name,Username,Account Active,Account Expiration"<br />foreach($username in $users){<br /> $user = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($ct, $username)<br /> $user."DisplayName" + "," + <br /> $username + "," + <br /> $user."Enabled" + "," + <br /> $user."AccountExpirationDate"<br />}Jeff Olsonhttps://www.blogger.com/profile/10359981784036083692noreply@blogger.comtag:blogger.com,1999:blog-4934393933440874074.post-14430207097209960532015-12-15T04:21:21.637-06:002015-12-15T04:21:21.637-06:00Thanks! This works perfectly.
How would you go abo...Thanks! This works perfectly.<br />How would you go about to export the result to a text file with columns and heads like Username DisplayName etc?<br /><br />Br<br />Niklasclawhammerhttps://www.blogger.com/profile/01734734793849220400noreply@blogger.com