Hello,
I was trying to reuse a VCENTER server connection in an start-JOB scriptblock, others commands are working fine like get-vm etc... but GET-Vdswitch or Get-VDportgroups reports the following error when are launched on a reconnected session
get-vdswitch
31-Aug-19 5:34:43 PM Get-VDSwitch No Lookup service information is available for this vCenter server.
+ CategoryInfo : InvalidOperation: (:) [Get-VDSwitch], VimException
+ FullyQualifiedErrorId : ViCore_ConnectivityServiceImpl_GetLookupServiceClient_NoClient,VMware.VimAutomation.Vds.Commands.GetVDSwitch
+ PSComputerName : localhost
31-Aug-19 5:34:43 PM Get-VDSwitch VDSwitch with name 'MYSWITCH' was not found using the specified filter(s).
+ CategoryInfo : ObjectNotFound: (:) [Get-VDSwitch], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.Vds.Commands.GetVDSwitch
+ PSComputerName : localhost
get-vdportgroup
get-vdportgroup : 31-Aug-19 5:22:18 PM Get-VDPortgroup No Lookup service information is available for this vCenter server.
At line:1 char:1
+ get-vdportgroup
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-VDPortgroup], VimException
+ FullyQualifiedErrorId : ViCore_ConnectivityServiceImpl_GetLookupServiceClient_NoClient,VMware.VimAutomation.Vds.Commands.Cmdlets.GetVDPortgroup
I'm using latest powercli version downloaded from powershellgallery
My Test Job is the following,
$block={
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$VCenter,
$vmSessID
)
$vcenter
$vmSessID
$null=Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings $false -ProxyPolicy NoProxy -Confirm:$false
Connect-Viserver $Vcenter -Session $vmSessID
get-vm VMTEST # this command works fine
get-Vdswitch -name 'MYSWITCH' # this command Fails
get-vdsportgroup # this also fails
}
JOB is started in the following way
$visession=connect-vicenter 'MyVicenter'
start-job -scriptBlock $block -argumentlist $Visession.name $Visession.SessionSecret
The only workaround I've found until now, was start this Job connection with a completely new session to the same VCenter.
But, there is a way to reuse / reconnect to an existing session for these commands?
Regards
That is a bit more circumstantial. SOmething like this
ForEach-Object -Process {
$netMgr = Get-View -Id $esx.ConfigManager.NetworkSystem
$netMgr.NetworkInfo.Portgroup |
Select @{N = 'VMHost'; E = { $esx.Name } },
@{N = 'Portgroup'; E = { $_.Spec.Name } },
@{N = 'VlanId'; E = { $_.Spec.VlanId } }
$netMgr.NetworkInfo.ProxySwitch |
ForEach-Object -Process {
Get-View -ViewType DistributedVirtualSwitch -Filter @{ Name = "$($_.DvsName)" } -PipelineVariable vds |
ForEach-Object -Process {
Get-View -Id $vds.Portgroup |
Select @{N = 'VMHost'; E = { $esx.Name } },
@{N = 'Portgroup'; E = { $_.Name } },
@{N = 'VlanId'; E = {
if ($_.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec])
{
$_.Config.DefaultPortConfig.Vlan.PvlanId
}
elseif ($_.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchVlanSpec])
{
if ($_.Config.DefaultPortConfig.Vlan.VlanId -is [VMware.Vim.NumericRange[]])
{
[string]::Join(',', ($_.Config.DefaultPortConfig.Vlan.VlanId | % { "$($_.Start)-$($_.End)" }))
}
else
{
$_.Config.DefaultPortConfig.Vlan.VlanId
}
}
}
} }
}
}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There are a couple of issues in your script.
When I do it like this, it seems to work perfectly.
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$VCenter,
$vmSessID
)
$null=Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings $false -ProxyPolicy NoProxy -Confirm:$false
Connect-Viserver $Vcenter -Session $vmSessID
Get-VM VMTEST
Get-VDSwitch -name 'MYSWITCH'
Get-VDPortgroup
}
$visession = Connect-VIServer -Server 'MyVCSA'
Start-Job -ScriptBlock $block -ArgumentList $Visession.name,$Visession.SessionSecret |
Wait-Job | Receive-Job
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
Thanks for checking.
To be sure to do the same, I've copied your test script.
But as you can see the problem is still there..
We are working with 6.0u3, may be is no fully compatible?
Unless you are using a rather old PowerCLI version, there should be no problem with that vSphere version.
Which PowerCLI version are you using?
Is your PSC embedded or separate?
Does it work when you do
Get-VDSwitch
Get-VDPortgroup
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Powercli version?
Was downloaded from Powershell gallery
PS C:\> get-powercliversion
PowerCLI Version
----------------
VMware PowerCLI 11.3.0 build 13990089
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component PowerCLI Component 11.3 build 13964830
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.3 build 13964826
And,
When I run command in the current session I don't have any trouble. Yes this one works well, without problem..
$visession = Connect-VIServer -Server 'MyVCSA'
Get-VDSwitch
Get-VDPortgroup
And If I change the way of connection inside my 'block' by a normal Connect-Viserver, then it works when I'll launch the start-job
Commands only fails when I use 'Connect-Viserver' with '-session' parameter.
REgards
Try like this.
This corresponds with the way I show it in my Running a background job dive.
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$VCenter,
$vmSessID
)
$null=Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings $false -ProxyPolicy NoProxy -Confirm:$false
Connect-Viserver $Vcenter -Session $vmSessID
Get-VM VMTEST
Get-VDSwitch -name 'MYSWITCH'
Get-VDPortgroup
}
Connect-VIServer -Server 'MyVCSA' | Out-Null
Start-Job -ScriptBlock $block -ArgumentList $Global:DefaultVIServer.name,$Global:DefaultVIServer.SessionSecret |
Wait-Job | Receive-Job
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Same result..:smileycry:
Is your PSC embedded or separate?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
Our setup is 'embedded'.
i've did 2 additional tests
I had the opportunity to try the test scrtip from another station that has version 6.5 of PowerCLI, and this time worked without problems. But I've had to modify a little the test script including the Import-Modules into the 'scriptblock' .
And I've also done a test using Get-View inside block using Get-view as you could see in the following lines, and this approach also works.
$viewSwitch=Get-view -viewtype DistributedVirtualSwitch -filter @{'NAME'='MYSWITCH'}
get-vdswitch -id $viewSwitch.moref
$viewPortGroup=Get-view -viewtype DistributedVirtualPortgroup
get-vdportgroup -id $viewPortGroup.moref
Then it looks like your 11.3 installation might have an issue.
What does this return on that station?
Get-PSSnapin
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PS C:\> get-module -Name VMware* -ListAvailable
Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 6.7.0.1... VMware.DeployAutomation {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-DeployRule...}
Script 6.7.0.1... VMware.ImageBuilder {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-EsxImageProfile, Export-Esx
Manifest 11.4.0.... VMware.PowerCLI
Script 6.7.0.1... VMware.Vim
Script 11.3.0.... VMware.VimAutomation.Cis.Core {Connect-CisServer, Disconnect-CisServer, Get-CisService}
Script 11.0.0.... VMware.VimAutomation.Cloud {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog...}
Script 11.3.0.... VMware.VimAutomation.Common
Script 11.3.0.... VMware.VimAutomation.Core {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHost, Add-V
Script 11.4.0.... VMware.VimAutomation.Hcx {Connect-HCXServer, Disconnect-HCXServer, Get-HCXAppliance, Get-HCXComputeProfile.
Script 7.9.0.1... VMware.VimAutomation.HorizonView {Connect-HVServer, Disconnect-HVServer}
Script 11.3.0.... VMware.VimAutomation.License Get-LicenseDataManager
Script 11.3.0.... VMware.VimAutomation.Nsxt {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtPolicyService, Get-NsxtService
Script 11.3.0.... VMware.VimAutomation.Sdk {Get-ErrorReport, Get-InstallPath, Get-PSVersion}
Script 11.0.0.... VMware.VimAutomation.Security {Get-SecurityInfo, Get-VTpm, Get-VTpmCertificate, Get-VTpmCSR...}
Script 11.2.0.... VMware.VimAutomation.Srm {Connect-SrmServer, Disconnect-SrmServer}
Script 11.4.0.... VMware.VimAutomation.Storage {Add-KeyManagementServer, Add-VsanObjectToRepairQueue, Copy-VDisk, Export-SpbmStor
Script 1.3.0.0 VMware.VimAutomation.StorageUtility Update-VmfsDatastore
Script 11.2.0.... VMware.VimAutomation.Vds {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGroup, Expor
Script 11.3.0.... VMware.VimAutomation.Vmc {Connect-Vmc, Disconnect-Vmc, Get-VmcSddcNetworkService, Get-VmcService...}
Script 10.0.0.... VMware.VimAutomation.vROps {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefinition...}
Script 6.5.1.7... VMware.VumAutomation {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance...}
PS C:\> get-pssnapin
Name : Microsoft.PowerShell.Core
PSVersion : 5.1.14393.3053
Description : This Windows PowerShell snap-in contains cmdlets used to manage components of Windows PowerShell.
How did your PowerCLI modules end up in C:\Windows\system32\WindowsPowerShell\v1.0\Modules?
I would expect C:\Program Files\WindowsPowerShell\Modules, when you installed them with Scope AllUsers.
What does $env:PSModulePath.Split(';') return?
As a possible solution, can you remove all the PowerCLI folders (manually).
Then restart your PS session, and do a Install-Module -Name VMware.PowerCLI?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello,
Not sure why modules were on different path, was not installed by myself. Modules were installed manually due some connectivity problems to use the corporate proxy.
But I was able to fix it (some TLS protocol issues with powershell) after that, I was able to perform a new install of VmWare modules using: ( Install-Module -Name VMware.PowerCLI ), installation finished without troubles.
Then I rerun the test Script that connects to VCenter reuusing the session, but the error continues occourring, seems that nothing has been changed.
Did you already check your DNS resolution (forward and reverse) on the station where you run the script and on the VCSA?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
VCSA is correctly setup for DNS (forward and reverse), but DNS registration on this site is quite particular because Reverse DNS is not configured for the rest of nodes.
And I don't have access to this server to temporary add an entry to hosts file to perform a test. I'll ask for it, but.. not sure if my request will be listened.
I'm thinking in possible alternatives,
The easiest one,
As connect-vicenter works when a new session is opened under 'start-process' session I'll probably continue with this option although is not the best one because this script was trying to deploy several VM in the less time possible.
Or another one, reusing the existing Session ID and using the get-view approach, but the problem with this one I' don't know how to filter the available standards portgroups available on ESX host that uses certains VLAN-ID, I use Vlan ID due we have a mixed enviroment with DsSwitches and Standard PorTgroups.
I found how to get VLAN-ID for Distributed portgroups, but not for Standards..
Regards
You could also, as an alternative, use the VICredentialStore.
At least you would not need to pass the credentials hardcoded in the Start-Job code.
You can find the VlanId, while using Get-View and both for VDS and VSS, like this
ForEach-Object -Process {
Get-View -id $_.Network |
select @{N='VM';E={$vm.Name}},
@{N='Portgroup';E={$_.Name}},
@{N='VlanId';E={
if($_ -is [VMware.Vim.DistributedVirtualPortgroup]){
if($_.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec]){
$_.Config.DefaultPortConfig.Vlan.PvlanId
}
elseif($_.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchVlanSpec]){
if($_.Config.DefaultPortConfig.Vlan.VlanId -is [VMware.Vim.NumericRange[]]){
[string]::Join(',',($_.Config.DefaultPortConfig.Vlan.VlanId | %{"$($_.Start)-$($_.End)"}))
}
else{
$_.Config.DefaultPortConfig.Vlan.VlanId
}
}
}
else{$_.VlanId}
}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Nice suggestions, thanks
But I need to find the VLAN-ID available for the portGroups attached to a host.
My script, after few tests determines the best place to deploy the VM. The data I'll have to determine network portgroup is the VLAN ID, and I need to filter PorTgroup configured on this host, but some hosts has both types of configuration.
I was trying to adapt your script for an esxHost, and there is no problem for configured Distributed switches, but I'm unable to get this information when there is some Standard PortGroups.
When I tried to find VLAN ID for standard porgroups the type is 'VMware.Vim.Network', are not ' VMware.Vim.DistributedVirtualPortgroup'
and after digging inside this type of object I can't see how to get VLAN ID data associated with it to determine the portgroup that I should associate with the VM.
That is a bit more circumstantial. SOmething like this
ForEach-Object -Process {
$netMgr = Get-View -Id $esx.ConfigManager.NetworkSystem
$netMgr.NetworkInfo.Portgroup |
Select @{N = 'VMHost'; E = { $esx.Name } },
@{N = 'Portgroup'; E = { $_.Spec.Name } },
@{N = 'VlanId'; E = { $_.Spec.VlanId } }
$netMgr.NetworkInfo.ProxySwitch |
ForEach-Object -Process {
Get-View -ViewType DistributedVirtualSwitch -Filter @{ Name = "$($_.DvsName)" } -PipelineVariable vds |
ForEach-Object -Process {
Get-View -Id $vds.Portgroup |
Select @{N = 'VMHost'; E = { $esx.Name } },
@{N = 'Portgroup'; E = { $_.Name } },
@{N = 'VlanId'; E = {
if ($_.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec])
{
$_.Config.DefaultPortConfig.Vlan.PvlanId
}
elseif ($_.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchVlanSpec])
{
if ($_.Config.DefaultPortConfig.Vlan.VlanId -is [VMware.Vim.NumericRange[]])
{
[string]::Join(',', ($_.Config.DefaultPortConfig.Vlan.VlanId | % { "$($_.Start)-$($_.End)" }))
}
else
{
$_.Config.DefaultPortConfig.Vlan.VlanId
}
}
}
} }
}
}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
- Reverse DNS
You suggested check Reverse DNS, but this feature is not configured by default on the site were I work, but My prayers were heard ;D, and my station was added to the 'host' file of our Vcenter Server
But unfortunately the problem with the 'No Lookup service information is available for this vCenter server' continues.
- I've realiced that there are other commands that fails when a previous session is reused with 'Connect-Viserver $Vcenter -Session $vmSessID ', For example, I've seen that Get-VmHost has te same problem, and fails with the 'No lookup service' error.
- To be sure that the problem was not cause by some security restriction or customization, I've also done this tests on a complete new installation of Windows 2016 without specific GPO that could perform some restrictions, but unfortunately the 'lookup' problem still continues.
At least In my environment,
Or I use a new connection using the normal 'connect-viserver' , with inconvenient that wi will have many simultaneous opened sessions if I launch multiple start-process. But at least it works.
Or I use your new script proposal that uses the get-view approach, that It works perfectly when I reuse the session.
I will probably use the Get-View script as alternative for me.
I'll really appreciate all the time that you have dedicated to me for this problem, thanks a lot!
And If you need or wants to continue investigating this problem and wants to perform some other checking, don't hesitate to tell me.
Regards
Thanks for sharing that info, and you're welcome :smileygrin:
You might try opening an SR, but that might take quite some effort from your side.
Plus they revamped the Lookup Service considerably in later vSphere version, not sure if they really want to dig very deep into this issue for your vSphere version.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference