Link to home
Start Free TrialLog in
Avatar of David Sankovsky
David SankovskyFlag for Israel

asked on

Adding a parameter to CSV output on PS

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
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Sankovsky

ASKER

That was it. Thanks a lot!