/// <summary> /// VerifyADFSAdministrationRights method implementation /// </summary> internal static void VerifyADFSAdministrationRights(PSHost host = null) { try { ClientSIDsProxy.Initialize(); if (!((ClientSIDsProxy.ADFSLocalAdminServiceAdministrationAllowed && ADFSManagementRights.IsAdministrator()) || (ClientSIDsProxy.ADFSSystemServiceAdministrationAllowed && ADFSManagementRights.IsSystem()) || (ClientSIDsProxy.ADFSDelegateServiceAdministrationAllowed && ADFSManagementRights.AllowedGroup(ClientSIDsProxy.ADFSAdminGroupName)) )) { throw new SecurityException("Access Denied !"); } } catch (Exception) { if (host == null) { throw new InvalidOperationException("Must be executed with ADFS Administration rights granted for the current user !"); } else { throw new InvalidOperationException("PS0033: This Cmdlet must be executed with ADFS Administration rights granted for the current user !"); } } }
/// <summary> /// VerifyADFSAdministrationRights method implementation /// </summary> internal static void VerifyADFSAdministrationRights() { ClientSIDsProxy.Initialize(); if (!((ClientSIDsProxy.ADFSLocalAdminServiceAdministrationAllowed && ADFSManagementRights.IsAdministrator()) || (ClientSIDsProxy.ADFSSystemServiceAdministrationAllowed && ADFSManagementRights.IsSystem()) || (ClientSIDsProxy.ADFSDelegateServiceAdministrationAllowed && ADFSManagementRights.AllowedGroup(ClientSIDsProxy.ADFSAdminGroupName)))) { throw new InvalidOperationException("PS0033: This Cmdlet must be executed with ADFS Administration rights granted for the current user !"); } }
/// <summary> /// VerifyPrimaryServer method implementation /// </summary> private static bool VerifyPrimaryServer() { ClientSIDsProxy.Initialize(); Runspace SPRunSpace = null; PowerShell SPPowerShell = null; try { SPRunSpace = RunspaceFactory.CreateRunspace(); SPPowerShell = PowerShell.Create(); SPPowerShell.Runspace = SPRunSpace; SPRunSpace.Open(); Pipeline pipeline = SPRunSpace.CreatePipeline(); Command exportcmd = new Command("(Get-AdfsSyncProperties).Role", true); pipeline.Commands.Add(exportcmd); Collection <PSObject> PSOutput = pipeline.Invoke(); foreach (var result in PSOutput) { if (result.BaseObject.ToString().ToLower().Equals("primarycomputer")) { return(true); } else { return(false); } } return(false); } finally { if (SPRunSpace != null) { SPRunSpace.Close(); } if (SPPowerShell != null) { SPPowerShell.Dispose(); } } }
/// <summary> /// VerifyPrimaryServer method implementation /// </summary> internal static void VerifyPrimaryServer() { ClientSIDsProxy.Initialize(); Runspace SPRunSpace = null; PowerShell SPPowerShell = null; try { SPRunSpace = RunspaceFactory.CreateRunspace(); SPPowerShell = PowerShell.Create(); SPPowerShell.Runspace = SPRunSpace; SPRunSpace.Open(); Pipeline pipeline = SPRunSpace.CreatePipeline(); Command exportcmd = new Command("(Get-AdfsSyncProperties).Role", true); pipeline.Commands.Add(exportcmd); Collection <PSObject> PSOutput = pipeline.Invoke(); foreach (var result in PSOutput) { if (!result.BaseObject.ToString().ToLower().Equals("primarycomputer")) { throw new InvalidOperationException("PS0033: This Cmdlet cannot be executed from a secondary server !"); } } } finally { if (SPRunSpace != null) { SPRunSpace.Close(); } if (SPPowerShell != null) { SPPowerShell.Dispose(); } } }