Пример #1
0
        public SPIaCRunspaceWithDelegate(SPIaCConnection connection)
        {
            // Create Initial Session State for runspace.
            InitialSessionState initialSession = InitialSessionState.CreateDefault();

            initialSession.ImportPSModule(new[] { "MSOnline" });

            // Create credential object.
            var credential = connection.GetActiveCredentials();

            // Create command to connect office 365.
            connectCommand = new PCommand.Command("Connect-MsolService");
            connectCommand.Parameters.Add((new CommandParameter("Credential", credential)));

            psRunSpace = RunspaceFactory.CreateRunspace(initialSession);
            // Open runspace.
            psRunSpace.Open();
        }
Пример #2
0
        /// <summary>
        /// Initializes the run space for the <paramref name="moduleName"/>
        ///     This module connection property must require Credentials
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="moduleName"></param>
        /// <param name="connectionCommand"></param>
        public void Initialize(SPIaCConnection connection, string moduleName, string connectionCommand)
        {
            // Create Initial Session State for runspace.
            InitialSessionState initialSession = InitialSessionState.CreateDefault();

            initialSession.ImportPSModule(new[] { moduleName });

            // Create credential object.
            var credential = connection.GetActiveCredentials();

            // Create command to connect office 365.
            connectCommand = new PCommand.Command(connectionCommand);
            connectCommand.Parameters.Add((new CommandParameter("Credential", credential)));

            psRunSpace = RunspaceFactory.CreateRunspace(initialSession);
            // Open runspace.
            psRunSpace.Open();
        }
Пример #3
0
        internal static SPIaCConnection InstantiateSPOnlineConnection(Uri url, string realm, string clientId, string clientSecret, string appDomain, string resourceUri, PSHost host, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, bool skipAdminCheck = false)
        {
            var authManager = new OfficeDevPnP.Core.AuthenticationManager();

            if (realm == null)
            {
                realm = url.GetRealmFromTargetUrl();
            }

            var context = authManager.GetAppOnlyAuthenticatedContext(url.ToString(), realm, clientId, clientSecret);

            context.ApplicationName = Resources.ApplicationName;
            context.RequestTimeout  = requestTimeout;

            var connectionType = ConnectionType.OnPrem;

            if (url.Host.ToUpperInvariant().EndsWith("SHAREPOINT.COM"))
            {
                connectionType = ConnectionType.O365;
            }

            if (skipAdminCheck == false)
            {
                if (IsTenantAdminSite(context))
                {
                    connectionType = ConnectionType.TenantAdmin;
                }
            }

            var connection = new SPIaCConnection(context, connectionType, minimalHealthScore, retryCount, retryWait, null, url.ToString())
            {
                AddInCredentials = new SPOAddInKeys()
                {
                    AppId  = clientId,
                    AppKey = clientSecret,
                    Realm  = realm
                }
            };

            return(connection);
        }