VMware vCLI “persistent login”
February 8th, 2010
No comments
Here is a short convenience script that will simulate a persistent login to a VMware host system when using the vCLI on Windows. Typically you have to specify a lot of parameters that include login information or a session file. With this method you just run the script and provide the hostname, username, and password for the connection.
After running this script you can run commands like “vicfg-mpath.pl –list” without additional parameters.
There is much that could be done to improve this script; this is just a quick and dirty version to make my life easier. If I improve it in the future I will post updates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #!/usr/bin/perl -w use strict; use warnings; my $vcli_install_dir = "C:\\Program Files\\VMware\\VMware vSphere CLI\\bin"; chdir($vcli_install_dir) or die "Could not change to the vCLI directory: $vcli_install_dir"; print "Hostname:"; my $host_name = <STDIN>; chomp($host_name); $ENV{'VI_SERVER'} = $host_name; my $session_file_name = $ENV{'TEMP'} . "\\vcli.session"; $ENV{'VI_SAVESESSIONFILE'} = $session_file_name; system("..\\Perl\\apps\\session\\save_session.pl"); $ENV{'VI_SESSIONFILE'} = $session_file_name; print "Spawning a logged in subshell. Type exit to end the session.\n"; system("cmd.exe"); # Remove the session file. unlink($session_file_name); |