RobMokkink
Expert
Expert

How to include Vi toolkit in powershell

Jump to solution

I installed the vi tookit, but i am only able to execute comand through the vmware vitoolkit and not straight to the standard powershell console. How do you enable that?

0 Kudos
1 Solution

Accepted Solutions
bshell
Enthusiast
Enthusiast

add-pssnapin VMware.VimAutomation.Core

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership

Add this to your Powershell profile.

Add-PSSnapin -Name "VMware.VimAutomation.Core"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

LucD
Leadership
Leadership

And if you're new to Powershell have a look at this profile info from Microsoft.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

RobMokkink
Expert
Expert

Hi Luc,

Thanks for your quick reply. Everything is working now

0 Kudos
bshell
Enthusiast
Enthusiast

add-pssnapin VMware.VimAutomation.Core

0 Kudos
acruizu
Enthusiast
Enthusiast

How do I call Initialize-VIToolkitEnvironment.ps1 from the profile?

0 Kudos
admin
Immortal
Immortal

You could "dot source" it:

. "$env:PROGRAMFILES\VMware\Infrastructure\VIToolkitForWindows\Scripts\Initialize-VIToolkitEnvironment.ps1"

0 Kudos
acruizu
Enthusiast
Enthusiast

Thank you. I got it. I just dot-source the file:

. Initialize-VIToolkitEnvironment.ps1

Comment a few lines and done.

0 Kudos
admin
Immortal
Immortal

To avoid red error messages if it's already in the environment I've been using:

& {

$ErrorActionPreference = "silentlycontinue"

$vmwareSnap = get-pssnapin -name "VMware.VimAutomation.Core"

if (! $?) { add-pssnapin "VMware.VimAutomation.Core" }

}

I bet there's a cleaner way.

0 Kudos
acruizu
Enthusiast
Enthusiast

I also try to make a function to initialize the vi toolkit, so I could call it when I want to load the snapin and the initialization script but I couldn't dotsource the initialization script for the current session.

0 Kudos