Avatar of David Sankovsky
David Sankovsky
Flag 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 {
    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?
PowershellActive DirectoryScripting Languages

Avatar of undefined
Last Comment
David Sankovsky

8/22/2022 - Mon