Hi LucD,
I was writing a script to install Open Server Management Server in ESXi host through PowerCLI. The script is able to series of steps like:
1) shutting down the VMs assciated with that ESXi host
2) putting the ESXi host in maintenace mode
3) installing OMSA
4) rebooting the ESXi host
5) changing the userVars.CIMoemProvdierEnabled bit to 1
6) exiting the host from maintenance mode and
9) Powering on VMs.
But I could not restart the management agents in ESXi host which was supposed to be the last part of the script.
I had been trying for this since a couple of days and through your posting I found that PowerCLI cannot directly restart the management agent. Thank you for this great information. Then I tried with the script you posted below. Through your script, I can login to the putty session but still not able to execute the command. I was going to giveup, but again I thought of asking for your help for the last time before I restart the agent manually.
And thanks again for your useful posts.
Note: Below is the script you posted on Oct 13, 2009. I could not figure out why the $remotecommand part is not working.
###################################################################################################
In Restarting the Management agents on an ESX or ESXi Server it says that, on ESX, you have to restart mgmt-vmware and vmware-vpxa. The last one can be done with the Get-VMHostService cmdlet but the other one is not manageable from PowerCLI.
As a bypass, you can use the plink.exe command (from the PuTTY suite), provided you allow root SSH access.
In that case you could use a script like this
$User = "root"
$Pswd = <root-password>
$hostName = <ESX-hostname>
$plink = "<PuTTY directory>\plink.exe"
$plinkoptions = " -v -batch -pw $Pswd"
$cmd1 = '/sbin/service mgmt-vmware restart'
$remoteCommand = '"' + $cmd1 + '"'
$command = $plink + " " + $plinkoptions + " " + $User + "@" + $hostName + " " + $remoteCommand
Invoke-Expression -command $command
$cmd2 = '/sbin/service vmware-vpxa restart'
$remoteCommand = '"' + $cmd2 + '"'
$command = $plink + " " + $plinkoptions + " " + $User + "@" + $hostName + " " + $remoteCommand
Invoke-Expression -command $command
On esxi there is no /sbin/service command that allows you to stop/start/restart specific daemons.
Remember, on ESXi there is no COS, instead you have the busybox which allows you start some, of the limited set of commands that are made available. Just run
/usr/bin/busybox
to see which commands are available.
if you look inside the /sbin/services.sh script, you'll notice that it manipulates all the daemons specified in /etc/chkconfig.db.
Taking the information from the script, you can see that to restart the management agent you can do
/etc/opt/init.d/vmware-vpxa restart
I hope this helps.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, LucD is right. How about typing services.sh restart in the SSH prompt, would that give the same result as well ?
Not exactly, it would work, but it would restart all daemons specified in /etc/chkconfig.db.
That's perhaps not what you want.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ah IC, os the command that you suggested before is restarting only the ESXi agent.
Thanks for letting us know here.
Thank you so much LucD. It worked perfectly.You really are a VMware guru. I still have one curiosity. Can we download any files or applications from websites using PowerCLI commands? To be more precise, can we download plink.exe file from the internet using PowerCLI? This time I manually downloaded plink.exe. If there is a way to download it through powerCLI, that would be awesome i.e. can automate a lot of things.
You can download plink.exe with the following PowerShell script:
$WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile("http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe","plink.exe")
If you want to change the path where plink.exe is saved to, you have to edit the last "plink.exe" on the second line of the script.
Regards, Robert
Hi Robert,
Thank you so much for your quick response and sorry for my late reply. Still I am having trouble downloading plink.exe through PowerCLI. At first I tried with your script without many any change. It gave me error "Exception calling "DownloadFile" with "2" argument (s): "The remote server returned an error: (407) Proxy Authentication Required."
Then I created a folder called "testing" in my windows host and gave the path C:\testing\ i.e.
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile("http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe","C:\testing\")
This time also it gave me error little different from the previous:
"Exception calling "DownloadFile" with "2" argument (s): "An exception occurred during a WebClient request."
Thank You.
The reason is this line is formatted wrong:
$WebClient.DownloadFile("http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe","C:\testing\")
Should be:
$WebClient.DownloadFile("http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe","C:\testing\plink.exe")
It seems that you use a proxy server that requires authentication. And the second parameter of the $WebClient.DownloadFile() requires the full path. So I changed the script into:
function Get-Webclient { $wc = New-Object Net.WebClient $wc.UseDefaultCredentials = $true $wc.Proxy.Credentials = $wc.Credentials $wc } $webclient = Get-WebClient $Url = "http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe" $Path = "C:\testing\plink.exe" $WebClient.DownloadFile($Url,$Path)
Can you try this? It works for me.
No sir, it's still showing the same error "Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (407). Proxy authentication Required."
function Get-Webclient {
$wc = New-Object Net.WebClient
$wc.UseDefaultCredentials = $true
$wc.Proxy.Credentials = $wc.Credentials
$wc
}
$webclient = Get-WebClient
$Url = "http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe"
$Path = "C:\testing\plink.exe"
$WebClient.DownloadFile($Url,$Path)
Thank You.
Hi LucD,
Regarding the "starting management agents via powercli", still the script could not meet the objective. The script you sent is able to restart the vmware-vpxa through plink.exe. And I thought everythig was fine and replied you back even before logging in to OMSA (my stupidity). Even after successful restarting of vmware-vpxa, the login to the OMSA server failed. Just to make sure I manually went to the "Troubleshoot options" and then restarted the management Agent through "Restart Management Options" of ESXi host without making any other change. Now I am able to login to the OMSA page.
Through script, it looks like that I am still missing to reboot the actual Management agent file. Any ideas or suggestions for the location of the Management Agent file will be greatly appreciated.
Thank You.
The script assumes that your default credentials are also the proxy credentials.
Perhaps that is not the case in your environment.
You can let the script prompt you for proxy credentials if that should be the case.
function Get-Webclient {
$wc = New-Object Net.WebClient
$wc.UseDefaultCredentials = $true
$wc.Proxy.Credentials = (Get-Credential).GetNetworkCredential()
$wc
}
$webclient = Get-WebClient
$Url = "http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe"
$Path = "C:\Temp\plink.exe"
$WebClient.DownloadFile($Url,$Path)
But if your proxy authentication is form-based, the above will not work either.
You will have to pass the Auth cookie in that case.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Do I understand correctly that the OMSA agent needs to be restarted ? As well ?
If you can find the script/binary behind the OMSA agent, you can probably restart it in a similar way.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OMSA agent does need not to be restarted. Only the ESXi Management Agents need to be restarted. If I Restart the ESXi Management manually going to Troubleshooting Mode Options, I am able to login to the OMSA. Restarting through the script, I have the feeling that apart from vmware-vpxa file in /etc/opt/init.d, there is some agent I am missing to restart.
If you run /sbin/services.sh you restart all services in the db.
Can you then logon to OMSA ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
awesome. After running /sbin/services.sh restart, I am able to login to the OMSA. Thanx a lot.
Thanx a lot to everyone who helped me especially Robert n Luc.
