VMware Cloud Community
shepnasty
Contributor
Contributor
Jump to solution

Where to save scripts

Went to VMWorld and attended PowerCLI session. I am a scripting NOOB and found a script that I want to run. I saved it to:

C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts

But when I go to run the script POWERCLI says it doesn't recognize the name of the script file. I am guessing this is because it isn't looking in the right spot. What am I doing wrong??

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could automate this by placing a 'cd <folder>' in your profile.

See Profile: Autostart Scripts for all the details on profiles.

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
5 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

If your script is called MyScript.ps1 and stored in C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts you can run the script with:

cd "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts"
.\MyScript.ps1

Or you can do:

&"C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\MyScript.ps1"

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
LucD
Leadership
Leadership
Jump to solution

If you downloaded the script from a website it could be that the execution policy in PowerShell is not set correctly.

You can change the execution policy with

Set-ExecutionPolicy RemoteSigned

or even

Set-ExecutionPolicy Unrestricted

which is of course a certain security risk.

Perhaps you could include the complete error message you're getting ?

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
shepnasty
Contributor
Contributor
Jump to solution

So you are saying I have to type the path everytime i want to run a script? There isn't a way to say this is where all of my scripts live?

0 Kudos
shepnasty
Contributor
Contributor
Jump to solution

I did run those commands during install. That is not the issue here.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could automate this by placing a 'cd <folder>' in your profile.

See Profile: Autostart Scripts for all the details on profiles.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos