How to import PowerCLI powershell modules/snapin and connect to vCenter

Opening the PowerCLI shortcut just to run a script gets a bit old when you basically live in it. I have scripts that I can open to do simple tasks like changing network adapters or adding a HDD, usually you would have to open the PowerCLI window and then cd to the directory where your scripts are and then execute them. Obviously that gets old, there is a better way! We can import the PowerCLI snapin and then automatically connect to your vCenter server. Heres how:


In this example you would have to add your vCenter server var to every script. That can get old as well, especially if you have a ton of scripts. A great way to fix this is to add a new environment variable to your computer (ie, vcserver = SERVER NAME), once that is done you can access that variable from any PS script by using $env:vcserver. Hope that helps!

0 comments… add one

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.