VMware Cloud Community
IKirill
Enthusiast
Enthusiast
Jump to solution

invoke-vmscript to check guest passwords

Hi! I have 500 Linux vms with 500 unique passwords in CSV.

For exaple:

vmname, login, password

vm1, root, www1

vm2, root, www2

How i can check this by invoke-vmscript?

In the finish i wont see CSV like this

vmname, login, password, passwordstatus

vm1, root, www1, Passwordok

vm2, root, www2, PasswordBAD

Sound like this, but i dont some understand

$Vmlist = import-csv -Path "C:\vmlist.csv" -Delimiter ";"

foreach ($vm in $Vmlist)

{

$vvm = $vm.vmname

$vlogin = $vm.login

$vpassword = $vm.password

@{N='vmname';E={$vvm}},

@{N='login';E={$vlogin}},

@{N='password';E={$vpassword}},

@{N='Passwordstatus';E={if "Invoke-VMScript -VM $vvm -ScriptType bash -ScriptText ifconfig -GuestUser $vlogin -GuestPassword $vpassword" not error then "Passwordok" else

"PasswordBAD"

}  |

Export-Csv -Path "C:\VMS-check.csv" -NoTypeInformation -UseCulture

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could combine that in the same Invoke-VMScript call that is used to determine that the password is ok,

Something like this

$Vmlist = import-csv -Path "C:\vmlist.csv" -Delimiter ";"

$report = foreach ($vm in $Vmlist)

{

    $vvm = $vm.vmname

    $vlogin = $vm.login

    $vpassword = $vm.password

    Try{

        $out = Invoke-VMScript -ErrorAction Stop -VM $vvm -ScriptText 'uname -mrs' -ScriptType Bash -GuestUser $vlogin -GuestPassword $vpassword

        $result = "Passwordok"

    }

    Catch{

        $out = ''

        $result = "PasswordBAD"

    }

    "" | Select @{N='vmname';E={$vvm}},

        @{N='login';E={$vlogin}},

        @{N='password';E={$vpassword}},

        @{N='Passwordstatus';E={$result}},

        @{N='BuildNumber';E={$out.ScriptOutput}}

}

$report | Export-Csv -Path "C:\VMS-check.csv" -NoTypeInformation -UseCulture

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

$Vmlist = import-csv -Path "C:\vmlist.csv" -Delimiter ";"

$report = foreach ($vm in $Vmlist

    $vvm = $vm.vmname 

    $vlogin = $vm.login 

    $vpassword = $vm.password

    Try{

        Invoke-VMScript -ErrorAction Stop -VM $vvm -ScriptText 'date' -ScriptType Bash -GuestUser $vlogin -GuestPassword $vpassword > $null

        $result = "Passwordok"

    }

    Catch{

        $result = "PasswordBAD"

    }

    "" | Select @{N='vmname';E={$vvm}}, 

        @{N='login';E={$vlogin}}, 

        @{N='password';E={$vpassword}}, 

        @{N='Passwordstatus';E={$result}}

}

$report | Export-Csv -Path "C:\VMS-check.csv" -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
IKirill
Enthusiast
Enthusiast
Jump to solution

thanks LUCD

may be the error ?


        @{N='Passwordstatus';E={$result}

}

} !!!!

$report | Export-Csv -Path "C:\VMS-check.csv" -NoTypeInformation -UseCulture

but output are saying, that all passwords bad, it's not true

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There was indeed a closing curly brace missing, I fixed it in the code above.

Just tested again, 2 rows with the same VM, same account but 2 different passwords (1 good and 1 bad), and it gave me the correct result.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
IKirill
Enthusiast
Enthusiast
Jump to solution

Ok, thanks again! i am trying)))

what if i wont to add to this script new column like

@{N='BuildNumber';E={invoke-VMScript -VM $vvm -ScriptText 'uname -mrs' -ScriptType Bash -GuestUser $vlogin -GuestPassword $vpassword}}

but column in CSV is empty!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could combine that in the same Invoke-VMScript call that is used to determine that the password is ok,

Something like this

$Vmlist = import-csv -Path "C:\vmlist.csv" -Delimiter ";"

$report = foreach ($vm in $Vmlist)

{

    $vvm = $vm.vmname

    $vlogin = $vm.login

    $vpassword = $vm.password

    Try{

        $out = Invoke-VMScript -ErrorAction Stop -VM $vvm -ScriptText 'uname -mrs' -ScriptType Bash -GuestUser $vlogin -GuestPassword $vpassword

        $result = "Passwordok"

    }

    Catch{

        $out = ''

        $result = "PasswordBAD"

    }

    "" | Select @{N='vmname';E={$vvm}},

        @{N='login';E={$vlogin}},

        @{N='password';E={$vpassword}},

        @{N='Passwordstatus';E={$result}},

        @{N='BuildNumber';E={$out.ScriptOutput}}

}

$report | Export-Csv -Path "C:\VMS-check.csv" -NoTypeInformation -UseCulture

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
IKirill
Enthusiast
Enthusiast
Jump to solution

Many thanks!!!

0 Kudos