Hello.
I'm trying to create a PowerCli Script to add and remove routes in a guest OS.
But with my current command, it fails saying:
Current script:
add-pssnapin VMware.VimAutomation.Core
set-PowerCLIConfiguration -invalidCertificateAction "ignore" -confirm:$false
$vCenter = "center_address"
$VCUser = "center_user"
$VCPassword = "center_password"
$VMUser = "Network admin with all permissions"
$VMPassword = "network password"
$VMName = "OPR-WIN7-20"
## Login
Connect-VIServer -Server $vCenter -User $VCUser -Password $VCPassword
## Get VM ID
$VM = Get-VM $VMName
## Add default gateway
$VM | New-VMGuestRoute -Destination 0.0.0.0 -Netmask 0.0.0.0 -Gateway 92.43.233.1 -GuestUser $VMUser -GuestPassword $VMPassword -Confirm:$false
Disconnect-VIServer -Server $vCenter -Confirm:$false
I've also tryed with just get-VmGuestRoute to see if there was something wrong with the above command.
As it is now, im thinking about if it could be something with the user? And im also unable to find any information about this on google
Are you running the script from a 32-bit PowerCLI session ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, Im running the script in a PowerCli 32Bit session.
Just like the Invoke-VMScript cmdlet, the New-OSGuestRoute cmdlet has a couple of prerequisites.
You could check with the script from my Will Invoke-VMScript work ? post if all the prereqs are met.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hmm, Im unable to run the function proberly.
When i paste the script in my shell, it makes ">>" on every new line, like its waiting for something
I have to CTRL+C to get back.
What did i do wrong?
Save my script in a .ps1 file.
Then from the PowerCLI prompt do
PS C:\> . .\filename.ps1
PS C:\> $vm = Get-VM MyVM
PS C:\> Test-InvokeVMScript -VM $vm
In the first line you dot-source the .ps1 file (there is a blank between the two dots).
That way the function is know/defined in your PowerCLI session.
Then call the function with the VM as parameter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Doing that, and running the function gets me:
Hello,
can you please test this ?
Invoke-VMScript -VM OPR-WIN7-20 -GuestCredential (Get-Credential) -ScriptType Powershell -ScriptText "route print"
Does this print the route table or do you get error ? Please run this as it is, and provide the credentials when asked
Ok, so there is prereq missing.
Add the -Detail parameter on the function call.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Command "Invoke-VMScript -VM OPR-WIN7-20 -GuestCredential (Get-Credential) -ScriptType Powershell -ScriptText "route print" " Doesnt not work.
Same error.
And using the detail parameter i get:
It looks as if port 902 is not open.
Do you have a Firewall active on your client or on the vCenter ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
All firewalls are disabled.
I've tryed to run the commands from another machine, where it worked fine? Which really bugs me
Perhaps another application or service is blocking port 902 ?
Does 'netstat -a' reveal anything ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Acording to Netstat -a, nothing is currently using port 902.
Both on the working and on the not working machine:
"
"
That is strange !?!
Does my function also marks port902 as False on the PC where the script seems to be working ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
On the working machine.
That's what to expect when the script is working ok.
But then I don't get why the telnet over port 902 doesn't work on that PC.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
My co-worker just said that its a windows machine, and it have telnet disabled.
Is telnet required for this to work?