internal static bool InitializeExchangePropertyContainerIfNeeded(ISessionState sessionState, out ADObjectId executingUserId, out OrganizationId executingUserOrganizationId) { executingUserId = null; executingUserOrganizationId = null; if (sessionState != null && !ExchangePropertyContainer.IsContainerInitialized(sessionState)) { ExTraceGlobals.LogTracer.Information(0L, "ExchangePropertyContainer is not initialized. Case of Service, Setup or Powershell with manually added snapin"); executingUserOrganizationId = TaskHelper.ResolveCurrentUserOrganization(out executingUserId); if (executingUserOrganizationId == null) { executingUserOrganizationId = OrganizationId.ForestWideOrgId; } ExchangePropertyContainer.InitExchangePropertyContainer(sessionState, executingUserOrganizationId, executingUserId); return(true); } return(false); }
internal static ExchangeRunspaceConfiguration UpdateExchangeRunspaceConfiguration(ISessionState sessionState) { WindowsIdentity current = WindowsIdentity.GetCurrent(); ExchangeRunspaceConfiguration exchangeRunspaceConfiguration = new ExchangeRunspaceConfiguration(current); if (!ExchangePropertyContainer.IsContainerInitialized(sessionState)) { ExchangePropertyContainer.InitExchangePropertyContainer(sessionState, exchangeRunspaceConfiguration); } else { ExchangePropertyContainer propertyContainer = ExchangePropertyContainer.GetPropertyContainer(sessionState); propertyContainer.exchangeRunspaceConfiguration = exchangeRunspaceConfiguration; if (propertyContainer.budget != null) { propertyContainer.budget.Dispose(); } propertyContainer.budget = ExchangePropertyContainer.AcquirePowerShellBudget(exchangeRunspaceConfiguration); } return(exchangeRunspaceConfiguration); }