Hi,
I've been trying to get around the issue that some users don't have permissions to set DRS cluster group membership by connecting an additional user ("service account") to the same VC who has "modify cluster" permissions.
I've tried specifying the server using -Server ($global:DefaultVIServers | ?{$_.User -eq $ServiceAccount}) and it works when running manually, but when I run it in a script file it throws below error:
Set-DrsClusterGroup : 2017-11-08 15:54:17 Set-DrsClusterGroup Permission to perform this operation was denied. Required
privilege 'Host.Inventory.EditCluster' on managed object with id 'ClusterComputeResource-domain-c5869'.
+ ... " | Set-DrsClusterGroup -Server ($Global:DefaultVIServers | ? ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-DrsClusterGroup], NoPermission
+ FullyQualifiedErrorId : Client20_ComputeResourceServiceImpl_SetDrsClusterGroup_ViError,VMware.VimAutomation.ViCore
.Cmdlets.Commands.SetDrsClusterGroup
I've tried disconnecting the user then connecting the service account and it works when running manually, but when I run it in a script file it throws below error.
Get-DrsClusterGroup : 2017-11-09 10:42:24 Get-DrsClusterGroup Server domain\username@vcenter.domain.local:443 is not connected.
+ ... Get-DrsClusterGroup -Type VMGroup -Cluster $Cluster -Name ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-DrsClusterGroup], ViServerConnectionException
+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryVerifyIsConnected_NotConnected,VMware.VimAutomation.Vi
Core.Cmdlets.Commands.GetDrsClusterGroup
Command: Get-DrsClusterGroup -Type VMGroup -Cluster $Cluster -Name $DRSGroup | Set-DrsClusterGroup -Add -VM $VMName
Powershell Version: 5.1.15063.674
PowerCLI Version: 6.5.2.6234650
It seems that the first user I connect with keep running commands even if I disconnect the user session and connect a new one when running it as a script, not as a terminal.
How can I switch user/connection in a script or specify which user/connection to use when running a command that does not have the -User parameter?