简体   繁体   中英

Run Bash command in script PS with Powercli

i try to run this script in powercli V.11 but i have always des mistakes.

$vm= "server"
$adminGuest="root"
$adminGuestPwd="pass"
$command =   " df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }'"
Invoke-VMScript -vm $vm -ScriptText $command -GuestUser $adminGuest -GuestPassword $adminGuestPwd -ScriptType Bash 

i don't know how can i integrate this script in my code df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }'

Thnks

Double quotes in awk command are confusing PowerCLI code check. If you try the command without double quotes in awk, you still won't get the result you're expecting as awk is not parsing the data properly.

Maybe you can collect info with Invoke-VMScript and then parse it somehow with Powershell.

$command =   " df -H | grep -vE '^Filesystem|tmpfs|cdrom' "
$output = Invoke-VMScript -vm $vm -ScriptText $command -GuestUser $vCUser -GuestPassword $vCPass -ScriptType Bash 
$output.ScriptOutput

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM