VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Invoke-VMScriptPlus shows No such file or directory

Hi,

I am getting "No such file or directory" for the below script when using Invoke-VMScriptPlus v3. Please help!!

Script

$pScript = @'
'/usr/bin/df -h'
echo
'cat /etc/redhat-release'
echo
uname -a
echo
pwd
'@

$sCode = @{
VM = "disktest"
GuestOS = 'Linux'
GuestCredential = $Cred
SkipCertificateCheck = $true
Verbose = $true
NoIPinCert = $true
ScriptType = 'bash'
ScriptText = $pScript
}

Invoke-VMScriptPlus @scode

 

Output Error:

PS D:\myreports\Invokeplus> .\invokeplus.ps1
VERBOSE: 03/07/2023 11:52:00 PM Get-View Finished execution
VERBOSE: 03/07/2023 11:52:00 PM Get-View Finished execution
VERBOSE: 03/07/2023 11:52:00 PM Get-View Finished execution
VERBOSE: 03/07/2023 11:52:00 PM Get-View Finished execution
VERBOSE: Seems to be a Linux guest OS
VERBOSE: Add SheBang #!/usr/bin/env bash
VERBOSE: Created temp folder in guest OS /tmp/vmware-root_1089-4013330115/user1_34448vmware248
VERBOSE: Created temp script file in guest OS /tmp/vmware-root_1089-4013330115/user1_34448vmware248/user1_34448vmware95
VERBOSE: Created temp output file in guest OS /tmp/vmware-root_1089-4013330115/user1_34448vmware248/user1_34448_outputvmware213
VERBOSE: Copying Data to /tmp/vmware-root_1089-4013330115/user1_34448vmware248/user1_34448vmware95
VERBOSE: HTTP/1.1 PUT with 90-byte payload
VERBOSE: received 33-byte response of content type
VERBOSE: Copied scripttext to temp script file
VERBOSE: Make script file executable
VERBOSE: Run script with '/tmp/vmware-root_1089-4013330115/user1_34448vmware248/user1_34448vmware95 > /tmp/vmware-root_1089-4013330115/user1_34448vmware248/user1_34448_outputvmware213'
VERBOSE: Wait for process to end
VERBOSE: Get output from /tmp/vmware-root_1089-4013330115/user1_34448vmware248/user1_34448_outputvmware213
VERBOSE: HTTP/1.1 GET with 0-byte payload
VERBOSE: received 452-byte response of content type
VERBOSE: Removed folder /tmp/vmware-root_1089-4013330115/user1_34448vmware248

PidOwner : root
ExitCode : 0
Finish : 03/08/2023 5:52:02 AM
ScriptType : bash
OutFiles :
GuestOS : Linux
Pid : 258235
ScriptSize : 90
VM : disktest
ScriptOutput : /tmp/vmware-root_1089-4013330115/user1_34448vmware248/user1_34448vmware95: line 2: /usr/bin/df -h: No such file or directory

/tmp/vmware-root_1089-4013330115/user1_34448vmware248/user1_34448vmware95: line 4: cat /etc/redhat-release: No such file or directory

Linux disktest 4.18.0-372.16.1.el8_6.x86_64 #1 SMP Tue Jun 28 03:02:21 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux

/tmp/vmware-root_1089-4013330115/user1_34448vmware248

ScriptText : #!/usr/bin/env bash
'/usr/bin/df -h'
echo
'cat /etc/redhat-release'
echo
uname -a
echo
pwd
Start : 03/08/2023 5:52:01 AM

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Can you try without the quotes?

$pScript = @'
/usr/bin/df -h
echo
cat /etc/redhat-release
echo
uname -a
echo
pwd
'@@


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Can you try without the quotes?

$pScript = @'
/usr/bin/df -h
echo
cat /etc/redhat-release
echo
uname -a
echo
pwd
'@@


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

That worked now. But when I try outfile parameter, I am getting the below error

$sCode = @{
VM = "disktest"
GuestOS = 'Linux'
GuestCredential = $Cred
SkipCertificateCheck = $true
Verbose = $true
NoIPinCert = $true
ScriptType = 'bash'
ScriptText = $pScript
OutFile = 'Myoutfile.txt'
}

Invoke-VMScriptPlus @scode

Exception calling "InitiateFileTransferFromGuest" with "3" argument(s): "File /tmp/vmware-root_1089-4013330115/adm.jmadhu_11672vmware46/my.txt was not found"
At D:\1_Invokeplus.ps1:251 char:1
+ $fileInfo = $gFileMgr.InitiateFileTransferFromGuest($moref, $auth, $S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException

You cannot call a method on a null-valued expression.
At D:\1_Invokeplus.ps1:256 char:1
+ $ip = $fileInfo.Url.split('/')[2].Split(':')[0]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At D:\1_Invokeplus.ps1:273 char:34
+ $fileContent = Invoke-WebRequest @sweb
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Invoke-WebRequest], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Retrieve of script output failed!Status
At D:\1_Invokeplus.ps1:275 char:1
+ Throw "Retrieve of script output failed!`rStatus $($fileContent.Statu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Retrieve of scr...iled!Status :String) [], RuntimeException
+ FullyQualifiedErrorId : Retrieve of script output failed!Status

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The OutFile parameter copies a file from where the script is running in the Guest OS.
But that file has to exist.
In the error, it looks like this file 'my.txt' does not exist.

A good example is present in the function's Help.
It creates the file, and then that file is retrieved via the OutFile parameter.

 

$pScript = @'
  Get-Content -Path .\MyInput.txt | Set-Content -Path .\MyOutput.txt
'@
$sCode = @{
  VM = $VM
  GuestCredential = $cred
  ScriptType = 'powershellv7'
  ScriptText = $pScript
  InFile = 'C:\Test\MyInput.txt'
  OutFile = 'MyOutput.txt'
}
Invoke-VMScriptPlus 

 

 


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much LucD. That worked perfectly 🙂

 

0 Kudos