VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot

Unable to execute program on remote VMs

Hi,

I am unable to execute the local program on remote VMs as I am getting the below error

The term 'C:\Program Files\JAM Software\TreeSize\TreeSize.exe' 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.

    + CategoryInfo          : ObjectNotFound: (C:\Program File...ze\TreeSize.exe:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

    + PSComputerName        : app1

Script

Connect-viserver 10.10.10.10

$servs = get-content .\vms.txt

ForEach ($serv in $servs)

{

$WPassword = "password"

$pass = ConvertTo-SecureString -AsPlainText $WPassword -Force

$Creds1 = New-Object System.Management.Automation.PSCredential ("admin", $pass)

$output = Invoke-Command -ComputerName $serv -Credential $Creds1 -ScriptBlock {&'C:\Program Files\JAM Software\TreeSize\TreeSize.exe' /DATE /EXPAND 1 /EXCEL "D:\$serv_Export.xlsx" /EXPANDABLEREPORT /EXTENSIONSLIST /TOPFILESLIST /PIECHART /TREEMAP /AGEOFFILES /EXTENSIONSPIECHART "D:\"}

}

0 Kudos
3 Replies
LucD
Leadership
Leadership

The default value for the ScriptType parameter on Invoke-VMScript is PowerShell for any Windows guest OS.

Add -ScriptType Bat to your Invoke-VMScript cmdlet.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot

Hi LucD,

I have modified the line as below, but still I am getting error

$output = Invoke-VMScript -VM $serv -ScriptText "C:\Program Files\JAM Software\TreeSize\TreeSize.exe" /DATE /EXPAND 1 /EXCEL "D:\$serv_Export.xlsx" /EXPANDABLEREPORT /EXTENSIONSLIST /TOPFILESLIST /PIECHART /TREEMAP /AGEOFFILES /EXTENSIONSPIECHART "D:\" -ScriptType BAT -GuestUser admin -GuestPassword "password"

Error

At D:\tree_export.ps1:8 char:105

+ ... Text {"C:\Program Files\JAM Software\TreeSize\TreeSize.exe" /DATE /EX ...

+                                                                  ~

You must provide a value expression following the '/' operator.

At D:\tree_export.ps1:8 char:105

+ ...  {"C:\Program Files\JAM Software\TreeSize\TreeSize.exe" /DATE /EXPAND ...

+                                                              ~~~~

Unexpected token 'DATE' in expression or statement.

    + CategoryInfo          : ParserError: (:) [], ParseException

    + FullyQualifiedErrorId : ExpectedValueExpression

But If I run the direct command works without any error

&"C:\Program Files\JAM Software\TreeSize\TreeSize.exe" /DATE /EXPAND 1 /EXCEL "D:\$serv_Export.xlsx" /EXPANDABLEREPORT /EXTENSIONSLIST /TOPFILESLIST /PIECHART /TREEMAP /AGEOFFILES /EXTENSIONSPIECHART "D:\"

0 Kudos
LucD
Leadership
Leadership

But that is another error, your quotes are not correct.


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

0 Kudos