VMware Cloud Community
thanos24
Enthusiast
Enthusiast
Jump to solution

import powercli dlls without installing powercli

is there a way to import powercli dlls and be able to execute powercli cmds in powershell scripts without installing vmware powercli?  I have used

Add-PSSnapin VMware.VimAutomation.Core

but that still requires i have powercli installed. i tried searching around for a method using PSD1 files to import all the DLLs for powercli but am having difficulty figuring that out.

So i want to be able to execute a powershell script with powercli cmds and have the powercli DLLs imported without having to install powercli?

thanks.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can start by looking in the registry on a machine where you have PowerCLI installed.

Check the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\VMware.Core branch.

To get a complete picture I would try to use procmon from SysInternals.

Start procmon and set it up to monitor powershell.exe.

Then start the PowerCLI prompt and inspect the procmon trace.


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

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Perhaps this post, called Learn How to Load and Use PowerShell Snap-ins can help.

But you still need to get the DLLs one way or the other on your station.


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

thanos24
Enthusiast
Enthusiast
Jump to solution

i saw that in my searching i will go ahead and give it a try, but what are the .dll's that i need to include from powercli there are quite a few in the install directory?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can start by looking in the registry on a machine where you have PowerCLI installed.

Check the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\VMware.Core branch.

To get a complete picture I would try to use procmon from SysInternals.

Start procmon and set it up to monitor powershell.exe.

Then start the PowerCLI prompt and inspect the procmon trace.


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

0 Kudos
thanos24
Enthusiast
Enthusiast
Jump to solution

thank you, i used proc mon and it pretty much used most of the .dll's , so i also looked in the registry as you mentioned and it was referencing

C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\VMware.VimAutomation.ViCore.Cmdlets.dll

i used these 2 sites

http://msdn.microsoft.com/en-us/library/windows/desktop/dd878297(v=vs.85).aspx

http://blogs.technet.com/b/heyscriptingguy/archive/2010/10/16/learn-how-to-load-and-use-powershell-s...

along with PowerGUI Script Editor, the script editor when i used issued the New-ModuleManifest cmdlet , actually came up with a nice gui to input all the values etc.. so i created the psd1 you see below, i then used "import-module -name c:\vmware.psd1" it imported but would fail with the following error

error

so then i removed the line defining the

# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess =
               '..\..\..\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\VMware.VimAutomation.Format.ps1xml'

after i changed it to not include the ps1xml file

# Format files (.ps1xml) to be loaded when importing this module

FormatsToProcess = @()

it would then load correctly using "import-module -name c:\vmware.psd1" but gave the following message

WARNING: Some imported command names include unapproved verbs which might make them less discoverable. Use the Verbose parameter for more detail or type Get-Verb to see the list of approved verbs.

but i was able to connect to the vcenter host Smiley Happy , see below for the psd1 file i built, just save this as vmware.psd1 and of course change paths according to your needs and make sure you ship along the .dll's and it will work fine.

#
# Module manifest for module 'vmware'
#
# Generated by: VCE Company LLC
#
# Generated on: 10/31/2012
#

@{

# Script module or binary module file associated with this manifest
ModuleToProcess = 'VMware.Vim.dll'

# Version number of this module.
ModuleVersion = '1.0'

# ID used to uniquely identify this module
GUID = 'a4b87d2e-259e-456e-914e-03391d74666e'

# Author of this module
Author = 'VCE Company LLC'

# Company or vendor of this module
CompanyName = 'VCE Company LLC'

# Copyright statement for this module
Copyright = '2012 VCE Company LLC'

# Description of the functionality provided by this module
Description = 'powercli modules'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = ''

# Name of the Windows PowerShell host required by this module
PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
PowerShellHostVersion = ''

# Minimum version of the .NET Framework required by this module
DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module
CLRVersion = ''

# Processor architecture (None, X86, Amd64, IA64) required by this module
ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @()            

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module
ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = @()

# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = 'Initialize-PowerCLIEnvironment.ps1'

# Functions to export from this module
FunctionsToExport = '*'

# Cmdlets to export from this module
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module
AliasesToExport = '*'

# List of all modules packaged with this module
ModuleList = @()

# List of all files packaged with this module
FileList = @()

# Private data to pass to the module specified in ModuleToProcess
PrivateData = ''

}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Great, very useful info. Thanks


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

0 Kudos
thanos24
Enthusiast
Enthusiast
Jump to solution

seems PowerGUI was loading the powercli snapin and i didn't know it, so i disable powergui from loading it and my method did not work. i figured it out i have update the .psd1 file content in my previous post...

so make you sure you save all content above into a .psd1 file

then make sure in the directory where you save the .psd1 file you have the following files from vmware powercli

VMware.Vim.dll

VMware.VimAutomation.Sdk.Impl.dll

VMware.VimAutomation.Sdk.Interop.dll

VMware.VimAutomation.Sdk.Types.dll
VMware.VimAutomation.Sdk.Util10.dll

VMware.VimAutomation.Sdk.Util10Ps.dll

VMware.VimAutomation.ViCore.Cmdlets.dll

VMware.VimAutomation.ViCore.Impl.dll

VMware.VimAutomation.ViCore.Interop.dll

VMware.VimAutomation.ViCore.Types.dll

VMware.VimAutomation.ViCore.Util10.dll

VMware.VimAutomation.ViCore.Util10Ps.dll

VMware.Security.CredentialStore.dll

VMware.VimAutomation.Format.ps1xml

Initialize-PowerCLIEnvironment.ps1

VMware.VimAutomation.dll-Help.xml

0 Kudos
sochry
Enthusiast
Enthusiast
Jump to solution

I don't believe this is 100% working.  If appears to work but after uninstalling PowerCLI, it ceases to load the snapins.  The first telltale sign is the error:  "Get-PowerCLIVersion : The term 'Get-PowerCLIVersion' is not recognized as the name of a cmdlet, function, script file,
or operable program."

0 Kudos