VMware Cloud Community
RobMokkink
Expert
Expert
Jump to solution

How to include Vi toolkit in powershell

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
Jump to solution

add-pssnapin VMware.VimAutomation.Core

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Add this to your Powershell profile.

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


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

LucD
Leadership
Leadership
Jump to solution

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
Jump to solution

Hi Luc,

Thanks for your quick reply. Everything is working now

0 Kudos
bshell
Enthusiast
Enthusiast
Jump to solution

add-pssnapin VMware.VimAutomation.Core

0 Kudos
acruizu
Enthusiast
Enthusiast
Jump to solution

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

0 Kudos
admin
Immortal
Immortal
Jump to solution

You could "dot source" it:

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

0 Kudos
acruizu
Enthusiast
Enthusiast
Jump to solution

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
Jump to solution

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
Jump to solution

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