VMware Cloud Community
drivera01
Enthusiast
Enthusiast
Jump to solution

any way to run a powershell script?

Is there any other way to be able to setup a script to be able to run by either double clicking it or some other way other than having to opening powercli and going to the script and running it.

It might not be the best way to do it, but to help out the people not use to running powercli it will help. The script I know is fine to run...we are running win2k8 if that matters

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can create a shortcut and under the properties do a run of PowerShell.exe.

As an argument you pass along the script that PowerShell should run.

In the script you make sure the PowerCLI pssnapin is loaded.

For example, the target of the shortcut could be

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "MyScript.ps1"

And in MyScript.ps1 you add

Add-PSSnapin VMware.VimAutomation.Core

before the script uses a PowerCLI cmdlet.


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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

You can create a shortcut and under the properties do a run of PowerShell.exe.

As an argument you pass along the script that PowerShell should run.

In the script you make sure the PowerCLI pssnapin is loaded.

For example, the target of the shortcut could be

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "MyScript.ps1"

And in MyScript.ps1 you add

Add-PSSnapin VMware.VimAutomation.Core

before the script uses a PowerCLI cmdlet.


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

Reply
0 Kudos
drivera01
Enthusiast
Enthusiast
Jump to solution

It says it needs this

: This cmdlet requires 32bit process. Please run PowerCLI in 32 bit mode.

Reply
0 Kudos
julienvarela
Commander
Commander
Jump to solution

Hi,

Replace %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "MyScript.ps1" by %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe -File "MyScript.ps1"

Julien

Regards, J.Varela http://vthink.fr
LucD
Leadership
Leadership
Jump to solution

Some PowerCLI cmdlets do indeed need to be run in the PowerShell 32-bit engine.

When on 64-bit system you have 2 PowerShell binaries to run:

32-bit  as C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

64-bit   as C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Select the appropriate one for your script.


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

Reply
0 Kudos
fabiendibot
Enthusiast
Enthusiast
Jump to solution

When you use powershell.exe to launch a script, you can use the "-noprofile" switch to use a fresh powershell session.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik you always have a fresh session when you run powershell.exe.

The NoProfile parameter says not to run any of the profile scripts for the session.

See here for the other available parameters.


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

Reply
0 Kudos
fabiendibot
Enthusiast
Enthusiast
Jump to solution

This is what i was saying with the "Fresh Session", but my english is kinda bad i guess 😕

Using this parameter allow you to test script and make it work on standard environnement.

Reply
0 Kudos
julienvarela
Commander
Commander
Jump to solution

-NoProfile Tells the PowerShell console not to load the current user’s profile.


You can have more information about powershell parameters here :  More Powerful Ways to Launch Windows PowerShell


Julien.

Regards, J.Varela http://vthink.fr
Reply
0 Kudos
drivera01
Enthusiast
Enthusiast
Jump to solution

Is there a way to place the shortcuts on everyone's desktop that has an account on the server so they can easily run it. As you can see I'm not a windows person..

Thank you for all the great info!!!

Reply
0 Kudos
julienvarela
Commander
Commander
Jump to solution

Place the shortcuts on "C:\Users\Public\Desktop", it is a hidden folder so you will need to show hidden files and folders.

Julien.

Regards, J.Varela http://vthink.fr