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
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
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
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
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
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!
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
Many thanks!!!