VMware Cloud Community
ImaRelic
Contributor
Contributor

Suppress output from Initialize-PowerCLIEnvironment

I've written a report generator in PowerCLI then compiled it using ps2exe.ps1.

The script calls Initialize-PowerCLIEnvironment.ps1. Everything works nicely except that I cannot specify -noconsole because that script has a number of write-host commands in it.

Is there a simple way to suppress that output from Initialize-PowerCLIEnvironment.ps1?

Any suggestions are appreciated.

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership

Why would you call Initialize-PowerCLIEnvironment.ps1?

Are you using a very old PowerCLI version?


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

Reply
0 Kudos
ImaRelic
Contributor
Contributor

I didn't know that I wasn't supposed to call Initialize-PowerCLIEnvironment

I'm using PowerCLI 6.5

Reply
0 Kudos
LucD
Leadership
Leadership

I would advise to upgrade to the latest version.
The primary reason being that PowerCLI is modules only (no more PSSnapin), installed from the PowerShell Gallery and later versions contain bug fixes, performance improvements and new features.
See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates for instructions on how to upgrade.

With the latest version (all modules) and when you are using PS v4 or higher, you profit from the module autoload feature.
A module is automatically loaded the 1st time you use a cmdlet from that module.

There still will be an annoying output when module VMware.PowerCLI is loaded (see also Eliminate, or provide option with | VMware PowerCLI ).
But since there are no cmdlets in that module (it's a wrapper to load all other PowerCLI modules), the autoload feature will not load that module.


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

Reply
0 Kudos
ImaRelic
Contributor
Contributor

Thank you very much.

I appreciate you taking the time to enlighten me.

Reply
0 Kudos
LucD
Leadership
Leadership

No problem, let me know how it goes.


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

Reply
0 Kudos
ImaRelic
Contributor
Contributor

I installed PowerCLI 11.2 from a web site called PowerShell Gallery. Would you happen to know how to uninstall it?

Several things stopped working.  There is nothing to uninstall in Programs and Features. I removed all of the modules in Powershell but it still reports that it's running 11.2.  I don't know where it put it and I can't figure out how to get rid of it.

Once again, I will appreciate any suggestions.

Reply
0 Kudos
LucD
Leadership
Leadership

The modules are installed in one of the directories that are shown $env:PSModulePath (separated with a semi-column).

With the following you can find where the PowerCLI modules are installed

Get-Module -Name VMware* -ListAvailable

dir.png

Since PS modules are nothing more than folders and files, you can just delete the folders related to each PowerCLI module.

Now stop/start your PS session, and the PowerCLI modules are gone.

What exactly stopped working when you installed PowerCLI 11.2.0?


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

Reply
0 Kudos
ImaRelic
Contributor
Contributor

I made a very big mistake getting into this now. I'm slammed with multiple critical projects at the moment and don't have the spare cycles to look into this.  I need to get things working again with 6.5 and then circle back and do this update the right way in the not distant future.  I guess, truth be told, I am delinquent for not having done this a year or two ago.

There were a few things that didn't work right away. I had gotten most corrected. This was still puzzling me.

I've got several VM's with a "/" in the name.  In the older version:

      Get-VM ($M.Name).Replace("/", "%2F")

worked nicely but not in 11.2.

It seems as though it should have been a trivial fix but I've run out of time.

Reply
0 Kudos
LucD
Leadership
Leadership

Then just remove 11.2.0 (as I described above) and reinstall 6.5


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

Reply
0 Kudos