Enthusiast
Enthusiast

Invoke-VMScript Response status code does not indicate success: 403 (Forbidden)

Jump to solution

Hi,

Hope you're all well.

I am using Invoke-VMScript to interact with Windows VMs.

Something strange is happening. On my Windows 10 machine every time I do an invoke-vmscript, it carries out the script successfully on the VM, but it does not ever bring back a success message or the correct output.

It only says "Invoke-VMScript Response status code does not indicate success: 403 (Forbidden)." Although the script runs as expected on the VM I am never given feedback from PowerShell of the output.

However, if I try the same things on Windows Server 2016 machine, the output comes back successfully.

Know what's wrong?

vSphere Client version 6.7.0.42000

VMware.CloudServices                    12.1.0.17002793

VMware.DeployAutomation                 7.0.0.15902843

VMware.ImageBuilder                     7.0.0.15902843

VMware.PowerCLI                         12.1.0.17009493

VMware.Vim                              7.0.1.16997275

VMware.VimAutomation.Cis.Core           12.1.0.16997582

VMware.VimAutomation.Cloud              12.0.0.15940183

VMware.VimAutomation.Common             12.1.0.16997174

VMware.VimAutomation.Core               12.1.0.16997984

VMware.VimAutomation.Hcx                12.1.0.17002966

VMware.VimAutomation.HorizonView        7.13.0.16985899

VMware.VimAutomation.License            12.0.0.15939670

VMware.VimAutomation.Nsxt               12.0.0.15939671

VMware.VimAutomation.Sdk                12.1.0.16997004

VMware.VimAutomation.Security           12.1.0.17009513

VMware.VimAutomation.Srm                12.1.0.17002371

VMware.VimAutomation.Storage            12.1.0.17001270

VMware.VimAutomation.StorageUtility     1.6.0.0      

VMware.VimAutomation.Vds                12.1.0.17001377

VMware.VimAutomation.Vmc                12.1.0.17008354

VMware.VimAutomation.vROps              12.0.0.15940184

VMware.VimAutomation.WorkloadManagement 12.1.0.17003628

VMware.VumAutomation                    12.1.0.16941488

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Enthusiast
Enthusiast

Wow I've actually fixed the issue. Amazing what you can do when you start to focus :smileylaugh:

I was bypassing proxy in

notepad $Profile

I had the contents of:

[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('proxyurlhere')

[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials

[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

Which was causing the 403 forbidden issue on Invoke-VMScript.

I have cleared the $Profile and now I receive a successful response from Invoke-VMScript.

View solution in original post

0 Kudos
8 Replies
Leadership
Leadership

I wonder why you expect an answer from the community, when you never seem to reply or give feedback on your threads.
Sorry, three strikes and you're out.


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

0 Kudos
Enthusiast
Enthusiast

I apologize, i was not aware. I will be a better community member now.

I am still new to forums

0 Kudos
Enthusiast
Enthusiast

I have rectified the mistakes.

I would appreciate if I can still receive assistance on this thread.

Thanks,

0 Kudos
Leadership
Leadership

What does a Get-PowerCLIConfiguration return?

Can you add the Verbose switch on the Invoke-VMScript line?

How are you calling Invoke-VMScript and with which parameters?

Can you eventually try with my Invoke-VMScriptPlus function and the Verbose switch?


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

0 Kudos
Enthusiast
Enthusiast

From Windows 10 box:

Get-PowerCLIConfiguration:

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout

                                                                                                  Seconds           

-----    -----------     ------------------- ------------------------  -------------------------- -------------------

Session  UseSystemProxy  Multiple            Ignore                    True                       300               

User                     Multiple            Ignore                                                                 

AllUsers                 Multiple            Ignore  

Verbose:

VERBOSE: Performing the operation "Invoke-VMScript" on target "Machine01".

VERBOSE: 03/11/2020 14:43:58 Invoke-VMScript Finished execution

Invoke-VMScript : 03/11/2020 14:44:06 Invoke-VMScript Response status code does not indicate success: 403 (Forbidden).

At line:14 char:1

+ Invoke-VMScript -VM $vm -ScriptText $Script -ScriptType Powershell  ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], ViError

    + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_DownloadFileFromGuest_DownloadError,VMware.VimAutomation.ViCore.Cmdlets.

   Commands.InvokeVmScript

From Windows Server 2016 box

Get-PowerCLIConfiguration:

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecation

                                                                       Warnings         

-----    -----------     ------------------- ------------------------  ------------------

Session  UseSystemProxy  Multiple            Ignore                    True             

User                     Multiple            Ignore                                     

AllUsers                                                                                

                                                                            

Verbose:VERBOSE: Performing the operation "Invoke-VMScript" on target "Machine01".

VERBOSE: 03/11/2020 14:52:22 Invoke-VMScript Finished execution

WARNING: This property is deprecated and will be removed in a following release. It has been added for

backwards compatibility with the string class that the Invoke-VMScript cmdlet used to return. Use the '

ScriptOutput' property instead.

VM           : Machine01

ExitCode     : 0

ScriptOutput :

               serialnumber                                         

               ------------                                         

               VMware-........................

              

              

              

Uid          : /VIServer=domain\username@vcenter:443/VirtualMachine=VirtualMachine-vm-2265

               6/VMScriptResult=-57437633_0/

Length       : 174

The way I'm running the Invoke-VMScript:

$Credential = Get-Credential

Get-Module -Name VMware* -ListAvailable | Import-Module

Connect-VIServer -Server vCenter1

$Script = @'

Get-WmiObject win32_bios |select serialnumber

'@

$VM = get-vm -Name Machine01

Invoke-VMScript -VM $VM -ScriptText $Script -ScriptType Powershell -GuestCredential $Credential -Verbose

Please note I've replace the VM name, vCenter name, and Username above to protect companies identity. I am also starting to suspect Firewall due to how complex the organisations rules are.

I will get back to you on the Invoke-VMScriptPlus as I need to figure out how to use it first.

Thanks

0 Kudos
Enthusiast
Enthusiast

Also to add, using other commands for the scripttext reveals that it actually performs successfully on the VM from the Windows 10 machines e.g. changing IP address or settings DNS. Just the response is always a failure

0 Kudos
Enthusiast
Enthusiast

Quick update. The response is successful from a colleagues Windows 10 machine, so won't be firewall as a I previously mentioned

0 Kudos
Enthusiast
Enthusiast

Wow I've actually fixed the issue. Amazing what you can do when you start to focus :smileylaugh:

I was bypassing proxy in

notepad $Profile

I had the contents of:

[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('proxyurlhere')

[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials

[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

Which was causing the 403 forbidden issue on Invoke-VMScript.

I have cleared the $Profile and now I receive a successful response from Invoke-VMScript.

View solution in original post

0 Kudos