3 Replies Latest reply on Feb 6, 2019 4:30 AM by LucD

    Unable to execute program on remote VMs

    ganapa2000 Enthusiast

      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:\"}

      }

        • 1. Re: Unable to execute program on remote VMs
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          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.

          • 2. Re: Unable to execute program on remote VMs
            ganapa2000 Enthusiast

            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:\"

            • 3. Re: Unable to execute program on remote VMs
              LucD Guru
              Community WarriorsUser ModeratorsvExpert

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