简体   繁体   中英

Powershell Array within Runas-Command

I wanted to write a little Script to check who has default credentials in my domain. For checking I wanted to use the runas-command (because I don´t know it better :D). I wrote the following script:

$pw = @("aaaaa","54321","12345");
$user = @("user1", "user2", "user3")
$domain = "mydomain"

for ($usercount = 0; $usercount -le $user.Length-1; $usercount++)
{
    for ($i = 0;$i -le $pw.Length-1; $i++)
    {
        runas /user=""$($domain)\$($user[$usercount])"" /password=""$($pw[$i])"" .\test.bat
        Write-Host "runas /user=""$($domain)\$($user[$usercount])"" /password=""$($pw[$i])"" .\test.bat"
    }
}

and the output looks nice but it won´t work...

runas /user="mydomain\user1" /password="aaaaa" .\test.bat
runas /user="mydomain\user1" /password="54321" .\test.bat
runas /user="mydomain\user1" /password="12345" .\test.bat
runas /user="mydomain\user2" /password="aaaaa" .\test.bat
runas /user="mydomain\user2" /password="54321" .\test.bat
runas /user="mydomain\user2" /password="12345" .\test.bat
runas /user="mydomain\user3" /password="aaaaa" .\test.bat
runas /user="mydomain\user3" /password="54321" .\test.bat
runas /user="mydomain\user3" /password="12345" .\test.bat

would be great if somebody could help me out with this one :-)

Just do an iex :

$pw = @("aaaaa","54321","12345");
$user = @("user1", "user2", "user3")
$domain = "mydomain"

for ($usercount = 0; $usercount -le $user.Length-1; $usercount++)
{
    for ($i = 0;$i -le $pw.Length-1; $i++)
    {
        iex "runas /user:""$($domain)\$($user[$usercount])"" /password:""$($pw[$i])"" .\test.bat"
    }
}

Nevermind, I programmed it using C# via ValidateCredentials. Should be more reliable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM