ricky73
Hot Shot
Hot Shot

create PowerCLI script - Windows task scheduler

Jump to solution

I read some doc about how to run my PowerCLI script to get my reports.

I understood It's necessary to initialize PowerShell environment to load required components and if you want to load all these ones,  you have to run the script Initialize-PowerCLIEnvironment.ps1. It's right?

If I open the link, which VMware Power CLI created during installation, it shows:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noe -c ". \"C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1

How Can I run my script (test.ps) by the previous line loading all components?

What do you suggest me please?

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

That is correct, there is no more need to run any kind of init script to load the PowerCLI modules.

They are loaded through the module autoload features.

Since the installation process has changed since PowerCLI is available through the PowerShell Gallery, I suggest to first read

Welcome PowerCLI to the PowerShell Gallery – Install Process Updates

and

Updating PowerCLI through the PowerShell Gallery


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

View solution in original post

25 Replies
LucD
Leadership
Leadership

Which PowerCLI version are you using?

In more recent versions you don't have to run this init script anymore, all loading is done through module auto loading (since PowerCLI 6.5.1, which is NOT 6.5 R1).


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

0 Kudos
ricky73
Hot Shot
Hot Shot

6.3 release 1 because vcenter is 6.0.0 so I'd like to keep version not too updated

0 Kudos
LucD
Leadership
Leadership

Not too sure why you need to stick on the older 6.3, that is no prereq for vCenter 6.

pcli.png

You're missing out on some major improvements.

One of the important ones is the move to all modules, no more PSSnapin.


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

0 Kudos
ricky73
Hot Shot
Hot Shot

so what version do you suggest me for vcenter 6.0.0 ?

0 Kudos
LucD
Leadership
Leadership

I would go for the latest 10.1.1, you can always return to the one you are using currently.

See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates for instructions on how to do the update.

But first check what PowerShell version you are currently using.

What is in $PSVersionTable.

Is that showing PowerShell 5.1? Or an earlier version?


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

0 Kudos
ricky73
Hot Shot
Hot Shot

It's the latest, that is 5.1 which I updated just before PowerCli installation.

I believed latest PowerCli 10.x uses enhanced features which are not available for my 6.0..0 vCenter so I prefer to keep just steps before 10.x

What do you think ? 6.5 or 10.x with vCenter 6.0.0 ?

0 Kudos
LucD
Leadership
Leadership

I'm afraid you interpret that incorrectly, it's not because PowerCLI 10.1.1 supports new features in 6.5 or 6.7, that you can't use that version with vSphere 6.

Those new features just will not work in 6.0.
It's not that the internal workings of PowerCLI cmdlet are different, you just have additional ones, or new parameters on existing cmdlets.


Btw, if you know that you are in vSphere 6, you shouldn't be calling newer features.


And that is also why there is a compatibility matrix!


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

0 Kudos
ricky73
Hot Shot
Hot Shot

LucD

if you know that you are in vSphere 6, you shouldn't be calling newer features.

That's right! infact this is main reason to not install last version, so I'm sure I'll get almost all features for my vCenter version.

0 Kudos
LucD
Leadership
Leadership

You don't seem to understand that this cumulative.

There is no reason to stay on an older PowerCLI version.
If the compatibility matrix shows that a version is compatible with your vSphere version , you will be able to use all features of that version.


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

0 Kudos
ricky73
Hot Shot
Hot Shot

I'll try to explain in different way.

If I installed vCenter PowerCLI 10.x and for example It uses function "K1" which is characteristic for only vCenter 6.5/6.7 , I will not able to use it because it's not provided inside vCenter 6.0.

If I use manual of PowerCLI 10.x,  I can make mistake and confuse myself because I don't know what is command for my vCenter;  if I have to create new script and I have to verify what function of Powercli are available for my older vCenter.

I understood that latest PowerCLI to use all features of previous version.

0 Kudos
LucD
Leadership
Leadership

I give up!


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

0 Kudos
ibuamod
Contributor
Contributor
Ok I have a similar problem, Powercli 6.5, I need to run a script from CMD and it's so hard ?! I don't know how this thing is called powerCli ?! what's powerful in it since it's not easy to trigger a script
0 Kudos
LucD
Leadership
Leadership

That remark is a bit misplaced imho.
Your problem is with Jenkins, and you insist on using an older PowerCLI version, with all the complications that version brings.

I pointed to a solution in your thread, did you even look at it, or even better, try it?

Btw, the 'power' in the name comes from the link with PowerShell.


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

0 Kudos
ricky73
Hot Shot
Hot Shot

LucD

look at the following thread PowerCLI on vCenter

to see if I explained better what I wanted to say.

LucD
Leadership
Leadership

No, I still see the same misconception about using an up to date PowerCLI version.

Btw, a reply that agrees to install PowerCLI on a vCenter would make me very wary about everything else that person says.

A newer version not only introduces new features, but also improvements and bug fixes.

Just have a look at the Release Notes.

But it's your choice, and like I said I give up on this thread.

I don't even have 6.3 anymore.


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

0 Kudos
kmruddyVMW
Enthusiast
Enthusiast

I'd like to take a second to echo what LucD has been saying.

The official VMware statement is to always be on the latest version of PowerCLI.

This is said for many reasons, most of which were outlined in the form of a blog post from the other thread you linked to: Which Version of PowerCLI is Right For Me? - VMware PowerCLI Blog - VMware Blogs

Basically:

  • There's no dependency or relation between vSphere and PowerCLI. Any dependency which may have existed, was removed many years ago.
  • PowerCLI is backwards compatible to any supported version of vSphere, therefore 10.1.1 works back to vSphere 5.5.
  • There were some major performance improvements that were made in the transition from 6.3R1 up to PowerCLI 6.5.1.
    • In your case, that means your commands and scripts will perform faster.
  • Each version of PowerCLI also includes bug fixes, therefore any issues you may be experiencing in 6.3R1 may be fixed in newer versions of PowerCLI.
    • So much so that if you create a support request concerning PowerCLI, support will ensure you're on the latest version of PowerCLI before moving forward with the request.
0 Kudos
ricky73
Hot Shot
Hot Shot

Ok, according to all suggestions, I'll migrate to latest version 10.x

But what powerCLI reference guide document I should have to use? I think for 10.x.

Let's suppose I need new function for my script and I found it in 10.x manual, how I detect if this feature is implemented or no in vCenter 6.0? Is there matrix which list for every function in what vCenter is available ?

I'm not saying about exist scripts because I know is guaranteed backward compatibility.

0 Kudos
LucD
Leadership
Leadership

The PowerCLI information is available in 2 formats.

  1. The Get-Help cmdlet, which is the standard PowerShell way of providing help for a cmdlet.
    1. Note that there are also about_ help topics, which discuss principles instead of a specific cmdlet. See for example Get-Help -Name about_obn
  2. The online documentation at VMware{code}. For the latest version see PowerCLI 10.1.1 In there are multiple links:
    1. On online version of the Get-Help content at Cmdlet Reference
    2. The Change Log. In there you will find changes and additions for each PowerCLI release, including notes on which feature was added/changed for which vSphere version.


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

0 Kudos
ricky73
Hot Shot
Hot Shot

I'm sorry but we are speaking 2 different languages, I'm not saying where I can find documentation about PowerCli 10.x

My question is another one, I'll try again to explain:

Let's suppose I need new function for my script and I found it in 10.x manual, how I detect if this feature is implemented or no in vCenter 6.0? Is there matrix which list for every function in what vCenter is available ?

PowerCLI 10.x could be provide function "A" for only vCenter 6.7 so if I used (unawares) this A function in vCenter 6.0.0, I'll get error or no result, right? I'd like to avoid it.

How can I verify functions which I'll use in PowerCLI 10.x, are good for vCenter 6.0 ?  There will be dedicated enhanced functions for only 6.5/6.7 vCenter, right?

I'm saying about new script which I'll create in future, not existing script which are compatible to new PowerCLI version.

0 Kudos