Skip to content

Instantly share code, notes, and snippets.

@jdkarpin
Created January 3, 2019 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdkarpin/a2f2d7df94340b220d66688313044e6d to your computer and use it in GitHub Desktop.
Save jdkarpin/a2f2d7df94340b220d66688313044e6d to your computer and use it in GitHub Desktop.
Code example to reconfigure VUM proxy
#Requires -Modules VMware.VimAutomation.Core
#Requires -Modules VMware.VumAutomation
function InitializeVUMService ([VMware.VimAutomation.ViCore.Types.V1.VIServer] $vSphereServer) {
$serviceInstance = Get-View ServiceInstance -Server $vSphereServer
$extensionMgr = Get-View $serviceInstance.Content.ExtensionManager -Server $vSphereServer
$vumExtension = $extensionMgr.FindExtension("com.vmware.vcIntegrity")
if ($vumExtension -eq $null) {
throw New-Object System.Exception -ArgumentList "Update Manager extension is not found for vSphere Server '$($server.Name)'"
}
#execute an Update Manager PowerCLI cmdlet, to load the necessary assemblies
$patch = Get-Patch -Id 0 -WarningAction SilentlyContinue
$vumWebService = New-Object IntegrityApi.IntegrityService
$vumUrl = $vumExtension.Server[0].Url
$vumWebService.Url = $vumUrl
$vumWebService.CookieContainer = New-Object System.Net.CookieContainer
$vumWebService.Timeout = 300000
$svcRefVum = New-Object IntegrityApi.ManagedObjectReference
$svcRefVum.type = "VcIntegrity"
$svcRefVum.Value = 'Integrity.VcIntegrity'
$serviceInstance = Get-View ServiceInstance -Server $vSphereServer
$sessionManager = Get-View $serviceInstance.Content.SessionManager -Server $vSphereServer
$vumServiceContent = $vumWebService.RetrieveVcIntegrityContent($svcRefVum)
$userSession = $vumWebService.VciLogin($vumServiceContent.sessionManager, $sessionManager.CurrentSession.UserName, $sessionManager.CurrentSession.Key, $sessionManager.CurrentSession.Locale)
return $vumWebService, $vumServiceContent
}
Try { Disconnect-VIServer * -Force -Confirm:$False -ErrorAction SilentlyContinue | Out-Null } Catch {}
$vi_server = Connect-VIServer -Server $DestinationvCenter -Credential $Credentials -ErrorAction Stop
$global:vumWebService, $global:vumServiceContent = InitializeVUMService $vi_server
$vumWebService.UpdateIntegrityOptions(
$vumServiceContent.optionManager, @(
@{"key" = "registry.proxy.ProxyPassword"; "value" = $vumConfiguration.Proxy.Password},
@{"key" = "registry.proxy.ProxyPort"; "value" = $vumConfiguration.Proxy.Port},
@{"key" = "registry.proxy.ProxyServer"; "value" = $vumConfiguration.Proxy.Server},
@{"key" = "registry.proxy.ProxyUserName"; "value" = $vumConfiguration.Proxy.UserName}
@{"key" = "registry.proxy.UseProxy"; "value" = $vumConfiguration.Proxy.UseProxy}
)
)
$ret = $vumWebService.QueryIntegrityOptions($vumServiceContent.optionManager, @())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment