Creating shortcuts for PowerCLI that automatically log you in.
- Ben Liebowitz
- 5
- 3964
So, I started a new job a couple of months ago and we have multiple vCenter environments. My friend & temporary co-worker, Brian Spagna (@bspagna) and I both wanted to have shortcuts to launch PowerCLI windows and have a different background color for each to easily identify which environment we were in. We thought it would be cool to have it automatically connect to it’s respective vCenter also!
I recommend you upgrade to the latest version of PowerCLI (6.5.1) for this via the PowerShell Gallery! You can find the whole walk-thru on how to install it here. Keep in mind, you’ll need to uninstall any previous versions before attempting to install via the PowerShell Gallery.
I not only wanted shortcuts, but I wanted the icons to be different as well. I started by creating JPGs with a plain white background that have a designation to tell me which vCenter I’m connecting to (for ex: VC1, VC2, VC3.) Then, I had to convert these to be .ICO files. I found a website where I can upload my JPG and it will convert to ICO and prompt to download. They don’t have to be perfect, just enough for you to identify later. If you want to share these shortcuts with others on the same server or team, save the .ICO files in a shared location.
Next, right click on the desktop, click NEW and then SHORTCUT.
In the TYPE THE LOCATION OF THE ITEM box, type/paste:
Make sure to change vCenter to the name of your vCenter at the end of the line. 🙂 Then click NEXT.
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "connect-viserver vCenter"
Enter the name of your shortcut (I used the vCenter name) and then click FINISH.
Repeat with your other vCenter Environments.
Now, we have 3 shortcuts, all with the same icon.
Right click on your first shortcut and go to PROPERTIES. Click CHANGE ICON.
Then click BROWSE.
Navigate to where you saved the ICO files. Select the icon for the shortcut you created. Click OPEN.
Make sure your ICON is visible. Then click OK.
Next, click the COLORS tab.
Then select the color background you want for that vCenter’s Window. You’ll see the background change in the window to show you want it will look like. I choose BLUE here. You may want to change the TEXT color too, depending on the background. Click OK.
** Recommendation – I’d avoid red text, or you won’t know when you have a failure (aka blood splatter) **
Before you click OK, click ADVANCED.
Select RUN AS ADMINISTRATOR and click OK. (You’ll have fewer problems with PowerShell if it’s running as administrator.)
Then click OK.
Now, you’ve got 3 shortcuts, each for its own separate environment.
Feel free to pin then to your taskbar! 🙂
I hope someone finds this as handy as I do!
Enjoy!
Ben Liebowitz, VCP, vExpert
NJ VMUG Leader
***** UPDATE 7/5/2017 *****
I decided I wanted these to start in the folder I keep all my scripts, so I changed the shortcuts to point to a PS1 file.
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -file e:\ps1\vmware\vcenter.ps1
########################################################################## # # Script to open PowerShell in a specific folder & connect to vCenter # Created by BLiebowitz on 7/5/2017 # ########################################################################## # Set directory location set-location e:\ps1\vmware # connect to vCenter connect-viserver vCenter
Ben Liebowitz, VCP, vExpert
NJ VMUG Leader
5 thoughts on “Creating shortcuts for PowerCLI that automatically log you in.”
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Thank you for the article. In the 6.5.1 documentation it states that this script is run Initialize-PowerCLIEnvironment.ps1 but I cannot find it in the modules directory. Has this been changed?
If you install via the PowerShell Gallery, like described in the walkthru, you shouldn’t have to call that PS1. It will load the PowerCLI modules automatically if you follow the directions. I launch PowerShell and type CONNECT-VISERVER vCenter… and I’m in. 🙂
I’m still trying to figure out why but when attempting to connect to vCenter 6.5 appliance it keeps prompting me for credentials. Not so when connecting to vCenter 6 Windws version.
Any ideas? 🙂
I had an issue like that in the past. Turned out to be a problem with SSO. Is the domain your primary SSO domain? Maybe try to remove it from SSO and then re-add it? Or restart the PSC and then the vCSA?
Hello,
inspiring even in 2020. Thank you, have a peaceful time ahead.
Peter