VMware Cloud Community
MrJohnson
Enthusiast
Enthusiast
Jump to solution

Running multiple scripts from a cmdlet

Hello All,

I have some .ps1 scripts that I would like to run from a single cmdlet.

Currently in my cmdlet I have the following:

powershell -command "& 'C:\MyScript01.ps1'

This works fine but when I add a second one I get the following error.

powershell -command "& 'C:\MyScript01.ps1'

powershell -command "& 'C:\MyScript02.ps1'

Results

The term 'C:\MyScript02.ps1' is not recognized as the

name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included

, verify that the path is correct and try again.

At line:1 char:2

+ & <<<<  'C:\MyScript02.ps1'

    + CategoryInfo          : ObjectNotFound: (C:\vHealthCheck...ndMemReport.ps1:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

How can I add a second line?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That should work, are you sure C:\MyScript02.ps1 exists ?


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

That should work, are you sure C:\MyScript02.ps1 exists ?


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

0 Kudos
MrJohnson
Enthusiast
Enthusiast
Jump to solution

I had a space between each line.  After removing the space everything worked.  Thank you very much...

powershell -command "& 'C:\MyScript01.ps1'

powershell -command "& 'C:\MyScript02.ps1'

0 Kudos