VMware Cloud Community
IKirill
Enthusiast
Enthusiast
Jump to solution

Invoke-VMScript and many Bash commands

Hi!

I have multiple bash commands.

In real time i type command, then enter, then enother command and enter again. etc

How i can use all command in 1 $script?

This dos'nt work:

$script = "

/sbin/pvresize

/sbin/lvresize

"

Invoke-VMScript -VM MyVM -ScriptType bash -ScriptText $script -GuestUser root -GuestPassword P@ssw0rd

Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try with a here-string

$script = @'

/sbin/pvresize

/sbin/lvresize

'@

Invoke-VMScript -VM MyVM -ScriptType bash -ScriptText $script -GuestUser root -GuestPassword P@ssw0rd


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try with a here-string

$script = @'

/sbin/pvresize

/sbin/lvresize

'@

Invoke-VMScript -VM MyVM -ScriptType bash -ScriptText $script -GuestUser root -GuestPassword P@ssw0rd


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

Reply
0 Kudos
IKirill
Enthusiast
Enthusiast
Jump to solution

Many thanks!

Reply
0 Kudos
NucleusVM
Enthusiast
Enthusiast
Jump to solution

Any variables defined inside $script, are not working. Any workaround?
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

They are, but it depends how you defined the script as inline text (with or without variable substitution), and if you escaped the dollar signs in the variables if you selected variable substitution.
Can you share you code, so I can have a look?


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

Reply
0 Kudos