troubleshooting Question

Adding a parameter to CSV output on PS

Avatar of David Sankovsky
David SankovskyFlag for Israel asked on
PowershellActive DirectoryScripting Languages
2 Comments1 Solution52 ViewsLast Modified:
Hi everyone, I have the following script:
$PWDtest = 'P@$$w0rd!'
function Test-ADCredential {
    [CmdletBinding()]
    Param
    (
        [string]$UserName,
        [string]$Password
    )
    if (!($UserName) -or !($Password)) {
        Write-Warning 'Test-ADCredential: Please specify both user name and password'
    } else {
        Add-Type -AssemblyName System.DirectoryServices.AccountManagement
        $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain')
        $DS.ValidateCredentials($UserName, $Password)
    }
}



Get-User -ResultSize Unlimited | % {
    If(Test-ADCredential -UserName $_.SamAccountName -Password $PWDtest){
        $_ | Select SamAccountName,WindowsEmailAddress
        }
    } | Export-Csv C:\Results.csv

Open in new window


What this script does is fairly simple, it runs on all the users in my domain, and tried to validate each user with the password specified in $PWDtest and throws all the successful hits into a CSV file.

It was built as part of a security Audit I once ran. I now need to run on another domain, but the leaving sysadmin told me that there are several problematic passwords that they used to use... I want to use on the new domain, but I'd like for the $PWDtest value to appear in the CSV as well and not only the username and the email... How can I achieve that?
ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 2 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 2 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004