Executing the Azure Active Directory Module (MSOL Commands) Power Shell commands from the C#


Executing the Azure Active Directory Power Shell commands from the C#.

What is a use of the Azure PowerShell Module?

Azure Active Directory Module (ADPS) for Windows PowerShell cmdlets for Azure AD administrative tasks such as user management, domain management and for configuring single sign-on.

Executing the Azure PowerShell from the C# code:

Most of the Azure administrative work performed through the PowerShell jobs only and some scenarios we have to execute PowerShell commands in C#.
            I am going to explain how to execute Azure PowerShell from the C#.
To start writing the code the first step is we need to install Azure PowerShell Module as mentioned below.

Install the Azure AD Module

The Azure AD Module is supported on the following Windows operating systems with the default version of Microsoft .NET Framework and Windows PowerShell: Windows 8.1, Windows 8, Windows 7, Windows Server 2012 R2, Windows Server 2012, or Windows Server 2008 R2.
First install the Microsoft Online Services Sign-In Assistant for IT Professionals RTW from the Microsoft Download Center. Then install the Azure Active Directory Module for Windows PowerShell (64-bit version), and click Run to run the installer package.

Scenario: Get the Security Group Name from Azure Active Directory by key word.


Code for the Console Application.

                                     Download Code 
using System;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Security;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            GetSecurityGroup();
        }

        public static void GetSecurityGroup()
        {
            try
            {
               
                // Create Initial Session State for runspace.
                InitialSessionState initialSession = InitialSessionState.CreateDefault();
                initialSession.ImportPSModule(new[] { "MSOnline" });
                // Assign username to variable.
                UserCredential.UserName = "UserName"; // Pass Your AD User Name

                string password = "Your Password"; //  Pass your Password
                // Create and assign secure password string.
                SecureString securePass = new SecureString();
                foreach (char secureChar in password)
                {
                    securePass.AppendChar(secureChar);
                }

                UserCredential.Password = securePass;
                // Create credential object.
                PSCredential credential = new PSCredential(UserCredential.UserName, UserCredential.Password);
                // Create command to connect office 365.
                Command connectCommand = new Command("Connect-MsolService");
                connectCommand.Parameters.Add((new CommandParameter("Credential", credential)));
                // Create command to get office 365 user.
                Command getGroupCommand = new Command("Get-MsolGroup");
                getGroupCommand.Parameters.Add((new CommandParameter("SearchString", "Pass your security group name")));
                              
                using (Runspace psRunSpace = RunspaceFactory.CreateRunspace(initialSession))
                {
                    // Open runspace.
                    psRunSpace.Open();
                    //Iterate through each command and executes it.
                    foreach (var com in new Command[] { connectCommand, getGroupCommand})
                    {
                        var pipe = psRunSpace.CreatePipeline();
                        pipe.Commands.Add(com);
                        // Execute command and generate results and errors (if any).
                        Collection<PSObject> results = pipe.Invoke();
                        var error = pipe.Error.ReadToEnd();

                        if (error.Count > 0)
                        {
                            return;
                        }
                        if(results.Count>0)
                        {
                         Microsoft.Online.Administration.Group Group = (Microsoft.Online.Administration.Group)results[0].BaseObject;
                                  string  Groupid = Group.ObjectId.ToString();
                                  string GroupName = Group.DisplayName;
                              
                       }

                       
                    }
                    // Close the runspace.
                    psRunSpace.Close();
                }
                //Cursor.Current = Cursors.Default;
            }
            catch (Exception)
            {
             
            }
        }
    }
}



Microsoft Dynamics Marketing(MDM) 2015 Course Content

Summary : Microsoft Dynamics Marketing 2015 Course Content

Module 1: Microsoft Dynamics Marketing Overview
Defining Microsoft Dynamics Marketing
Target Customers
The Microsoft Dynamics Marketing and Dynamics CRM Relationship

Module 2: Dynamics Marketing Architecture
Microsoft Dynamics Marketing and Dynamics CRM Integration Overview
Email Marketing Overview
SDK Overview
Data Feed Overview

Module 3: Configuring Microsoft Dynamics Marketing
User Management
Company Hierarchical Structure
Contact Structure
Client Management
Key Administrative Settings

Module 4: Marketing Resource Management
Project Hierarchy
Choosing the Right Structure
Job Templates
Job Request Templates
Time Slips
Budget Management
Digital Asset Management and Approvals for Projects
Create products and virtual teams.
Create and test an Approval Request Template

Module 5: Lead Management
The Lead Lifecycle
Landing Page Basics and Lead Generation
Importing Leads
Lead Assignment Engine
Lead Scoring Models
•Segmenting Leads: Managing Marketing Lists
•Use Custom Contact Fields and Lead Interaction UDFs in Landing Pages.

Module 6: Email Marketing Messages and Landing Pages
Commercial Email Marketing Messages
Segment-Specific Dynamic Content
Campaign Automation versus Commercial Designation Email Marketing Messages
Cross-Campaign Rules
Best Practices for Avoiding the Junk Folder
Customizing Landing Page Content
Generating Traffic to a Landing Page
Create a commercial email marketing message with dynamic content for two marketing segments.
Customize a landing page with a source code, subscription list, and Header HTML to adjust the look and feel.
Module 7: Campaign Automation
Microsoft Dynamics Marketing Campaign Lifecycle
Campaign Activities: Marketing Lists, Actions and Triggers
Creating and Using Social Media
Validating and Activating a Campaign, and Email Activation Troubleshooting
Monitoring and adjusting the Campaign Mid Flight
Module 8: Measuring Results
Performance Reports
Widgets
Email Marketing Performance
Search Engine Monitoring
Budgets for Financial Monitoring
Using the OData Feed API
Module 9: Dynamics CRM and Dynamics Marketing Integration
Connector Architecture
Integrated Data
Connector Mappings
List Sync
Connector Scenarios
Module 10: MDM for the Developer
Traceable Transactional Emails
Razor Syntax in Emails
Contact External Entities
Marketing List Management
Bibliography of Resources
Razor Emails
Traceable Transactional Emails

Module 11: Setting Up a Deployment for Success

The Deployment Team
Tips for Planning a Deployment: Lessons Learned

Popular Posts