PowerCLI

 View Only
Expand all | Collapse all

any way to run a powershell script?

  • 1.  any way to run a powershell script?

    Posted Jul 14, 2013 01:27 AM

    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



  • 2.  RE: any way to run a powershell script?
    Best Answer

    Posted Jul 14, 2013 05:42 AM

    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.



  • 3.  RE: any way to run a powershell script?

    Posted Jul 14, 2013 07:03 AM

    It says it needs this

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



  • 4.  RE: any way to run a powershell script?

    Posted Jul 14, 2013 07:28 AM

    Hi,

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

    Julien



  • 5.  RE: any way to run a powershell script?

    Posted Jul 14, 2013 07:51 AM

    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.



  • 6.  RE: any way to run a powershell script?

    Posted Jul 14, 2013 07:54 AM

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



  • 7.  RE: any way to run a powershell script?

    Posted Jul 14, 2013 08:16 AM

    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.



  • 8.  RE: any way to run a powershell script?

    Posted Jul 14, 2013 09:01 AM

    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.



  • 9.  RE: any way to run a powershell script?

    Posted Jul 14, 2013 09:18 AM

    -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.



  • 10.  RE: any way to run a powershell script?

    Posted Jul 14, 2013 05:13 PM

    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!!!



  • 11.  RE: any way to run a powershell script?

    Posted Jul 14, 2013 05:58 PM

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

    Julien.