clear
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$dsa_filedlg= new-object System.Windows.Forms.OpenFileDialog
$app = new-object -com Shell.Application
$cred_filedlg = New-Object system.Windows.Forms.OpenFileDialog
###TODO: Open File Dialog to select DSA Executable File
Read-Host "Press 'ENTER' to select DSA Exe File..."
$dsa_filedlg.ShowHelp = $true
$ret_val=$dsa_filedlg.ShowDialog()
if($ret_val -eq "OK")
{
$dsa_filename = $dsa_filedlg.FileName
}
Write-Host "DSA Exe FilePath: " $dsa_filename -ForegroundColor Green
###TODO: Open Folder Dialog to select output folder for DSA logs
Read-Host "Press 'ENTER' to select output folder..."
$dsa_flddlg = $app.BrowseForFolder(0, "Select Folder", 0, "C:\")
if ($dsa_flddlg.Self.Path -ne "")
{
write-host "Output Folder Path " $dsa_flddlg.Self.Path -ForegroundColor Magenta
}
###TODO: Select credentials file which contains login credentials for individual ESX servers
###INFO: The credentials file is generated with the "New-VICredentialStoreItem" command
Read-Host "Press 'ENTER' to select Credentials File...(XML File)"
$cred_filedlg.ShowHelp = $true
$ret_val=$cred_filedlg.ShowDialog()
if($ret_val -eq "OK")
{
$cred_filename = $cred_filedlg.FileName
}
Write-Host "Credentials FilePath: " $cred_filename -ForegroundColor Yellow
#------------------------------------------------------------------------------------
Add-PSSnapin vmware.vimautomation.core
connect-viserver <vCenter Server> ###INFO: Enter ServerName/IP of the vCenter Server
$hosts = Get-VMHost
disconnect-viserver <vCenter Server> -WarningAction SilentlyContinue
foreach($esx_host in $hosts)
{
###INFO: The below 5 lines are to get the Hostname from a Domain Name of ESX host
$temp=$esx_host.name
Write-Host $temp
$index=$temp.IndexOf(".")
$sub=$temp.Substring(0,$index)
$sub
$pwd = Get-VICredentialStoreItem -Host $sub -File $cred_filename
$exec_command = $dsa_filename + ' -v -c -d ' + $dsa_flddlg.Self.Path + '\' + $sub + ' --vmware-esxi ' + $pwd.User + ':"' + $pwd.Password + '"@' + $sub
[System.Windows.Forms.MessageBox]::Show($exec_command)
Invoke-Expression -Command $exec_command
}
Advertisement
SocialVibe