PowerShell – Create users in Dynamics 365

To Create a user in Office 365 which will then percolate to as a user in Dynamics 365 we need to do the following:

  1. Login to Dynamics (Office 365)
  2. Create a user in office 365
  3. Assign Dynamics License to that user
  4. Wait for a few minutes and check in dynamics the user should be created as enabled.

Pre-Requisites:

Setup your local machine for executing Azure and Office PowerShell Scripts. For more details refer this link: https://docs.microsoft.com/en-us/office365/enterprise/powershell/connect-to-office-365-powershell .

Open PowerShell in admin mode, then do the following steps:

Step 1)

Install-Module -Name AzureAD

Step 2)

Install-Module MSOnline

Step 3)

Import-Module MSOnline

Note: At this step you might get an exception to install only digitally signed assemblies, to overcome this we can execute the following command.

Step 3.1)

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Step 4)

Connect-MsolService

Step 5) Following function encapsulates user creation with parameters

In the following code “DYN365_ENTERPRISE_PLAN1” is the license plan name for the organization when I created , it might be different for you based on your subscriptions.

$tenantName = "sayantanadobe"
$crmlicense = $tenantName+":DYN365_ENTERPRISE_PLAN1"
function CreateUser([string] $displayName,[string] $firstName,[string] $lastName,[string] $upn,[string] $license,[string] $tenantName)
{
$fullupn = "{0}@{1}.onmicrosoft.com" -f $upn, $tenantName
New-MsolUser -DisplayName $displayName -FirstName $firstName -LastName $lastName -UserPrincipalName $fullupn  –Department Operations -UsageLocation US -LicenseAssignment $license -ForceChangePassword $FALSE -Password pass@word1
}

Step 6) Now call the above function with the following statement to create a new user

CreateUser "Test User" "Test" "User" "test1" $crmlicense $tenantName
  • Thank You
Advertisements

ITIL 2011 : Brief Overview of Stages and Processes in ITIL 2011

  • Service Strategy
    • Service Portfolio Management
    • Demand Management
    • Financial Management
    • Business Relationship Management.
  • Service Design
    • Design Coordination
      • Output is SDP (Service Design Package given to Service transition)
    • Service Level Management (SLA)
    • Catalog management.
    • Availability Management
    • Capacity Management (CMIS)
    • Information Security Management
    • IT service Continuity Management
    • Supplier Management System
  • Service transition
    • Change Management
    • Service Asset and Configuration management (DML)
    • Release and Deployment Management
    • Knowledge management (Data information knowledge wisdom)
  • Service Operation
    • Event Management
    • Incident Management
    • Problem Management (KEDB)
    • Request Fulfillment
    • Access Management
    • Application Management
    • IT Operations Management
      • IT operation Control.
      • Facilities Management.
    • Service Desk.
  • CSI
    • PDCA (Deming Cycle) Plan do check act.

Monogame in Windows Phone 8

Windows phone offers a great platform for game developers to develop games for the mobile device. With the introduction of Windows Phone 7 developers had the option of creating games for windows phone in XNA 4.0 and DirectX. However XNA is no longer natively supported in Windows Phone 8 (XNA games still work on Windows Phone 8 but they work in a “compatibility mode”) and one is limited to usage of XAML with Direct3D technology to create games. The Direct3D component requires one to write code in C++ which in today’s modern world may not be a first choice for developers, at least for the native application programmers. So one has to either learn C++ to start using Direct3D and even though he does learn C++ he has to still learn Direct3D (assuming he is not familiar with Direct3D). The solution to the above problem lies in Monogame.

A first you might say, I need to learn another technology. But it’s not a new technology but just old things packaged into a new one. Monogame has already been available into other platforms like Android and iOS. Monogame inherently uses the Microsoft XNA 4 Application Programming Interface and also has the same Content Management Pipeline. For graphics rendering Monogame 3.0 uses OpenGL 2 shaders. Monogame also uses the SharpDX libraries to expose and utilize the full DirectX capabilities.

Monogame is an open source project and is available at GitHub at the following location https://github.com/mono/MonoGame. The installer for Visual Studio 2010/2012 is available at http://monogame.codeplex.com/releases/view/102870.

We shall now see how to create games using Monogame.

Creating your first Monogame Project:

After you have installed Monogame 3.0 start Visual Studio 2012 and then create a New Project. Creating a new project gives you the following window as shown in Figure 1.

If you have installed Monogame successfully then you can see Monogame in the left Navigation below Visual C#. If you click on the Monogame link you will see the various Visual Studio Templates that Monogame comes with. We will be using the first one in the list, i.e. Monogame Windows Phone 8 Project.

Create the project with name “BallBalancer”. This application will have a ball placed on your phone screen and it will roll over in the direction you tilt your phone.

After creating the project we would get a set of files generated by the Monogame template as shown in the Figure 2.

You will see that apart from the regular Windows Phone 8 project files created for a XAML project and addition file named Game1.cs is created. This file is the one that is similar to the XNA Game file. Let’s rename it to BallBalancerGame.cs.

Open the BallBalancerGame.cs file and you will see that it has 5 overridden methods apart from the constructor. If you by now realize it is the same game file that you generate in XNA games.

Next, let’s create a new solution folder and name it “Content”.

This folder will contain the XNA objects that we will use in our games, in our case we will add a pre-compiled ball graphics.

Note: Currently the Monogame project does not support the Content Processing features provided by XNA 4.0 project and hence we will have to compile our game resources in XNA and then add them into our project.

In our case we have an already compiled Ball graphics added to the project as shown below in Figure 3.

We will now create a class for handling the Ball data. Let’s create a new class and name it GameBall.cs as shown in Figure 3. The code for GameBall.cs is contained in Figure 4. The GameBall class contains two variables Position and Texture where Position holds the current position of the Ball and the Texture variable holds the graphics part of it. We also create a bounding rectangle using the Texture variable to check for collisions, rest of the methods are self-explanatory.

public class GameBall {
 private Vector2 _position;
 private Texture2D _texture;

public Vector2 Position
 {
 get { return _position; }
 set { _position = value; }
 }

public Texture2D Texture
 {
 get { return _texture; }
 set { _texture = value; }
 }

// Bounds of the ball, currently approximated to a rectangle
 public Rectangle Bound
 {
 get
 {
 return new Rectangle((int)_position.X + 5, (int)_position.Y + 5, _texture.Width - 5, _texture.Height - 5);
 }
 }

//Change the position of the ball by 'p' value
 public virtual void Move(Vector2 p)
 {
 _position += p;
 }

//Draws the Ball in every update
 public virtual void Draw(SpriteBatch _spriteBatch)
 {
 _spriteBatch.Draw(_texture, Position, Color.White);
 }

//Check collision with phone boundary walls
 internal void CheckCollision()
 {
 if (Position.X < 0)
 Position = new Vector2(0, this.Position.Y);
 if (Position.X + Texture.Width > BallBalancerGame.SCREEN_WIDTH)
 Position = new Vector2((float)(BallBalancerGame.SCREEN_WIDTH - Texture.Width), this.Position.Y);

if (Position.Y < 0)
 Position = new Vector2(this.Position.X, 0);
 if (Position.Y + Texture.Height > BallBalancerGame.SCREEN_HEIGHT)
 Position = new Vector2(this.Position.X, (float)(BallBalancerGame.SCREEN_HEIGHT - Texture.Height));
 }
 }
 

Now let’s add some game logic to the BallBalancerGame.cs file. In this class add the following variables, where SCREEN_HEIGHT and SCREEN_WIDTH are the height and width of the screen which we will set in the “Initialize” method. The variable ACCELERATION stores the speed at which the ball will move in the game. _motion is variable to the windows phone 8 Motion sensor API.

private SpriteBatch _spriteBatch;
private Motion motion;
private GameBall _gameBall;
public static double SCREEN_HEIGHT;
public static double SCREEN_WIDTH;
private const float ACCELERATION = 20;

After we have declared the variable lets add the following code into the “Initialize()” function. This code first sets the screen height and width based on the graphics device, then it tries to check if the device supports motion sensor using the Motion Sensor API found in Microsoft.Devices.Sensors namespace. If the device supports the Motion sensors then we will initialize it with an update interval set to 20 milliseconds and start the Motion API.

 SCREEN_HEIGHT = GraphicsDevice.Viewport.Height;
 SCREEN_WIDTH = GraphicsDevice.Viewport.Width;

_gameBall = new GameBall();

if (!Motion.IsSupported)
 {
 MessageBox.Show("This device doies not support the Motion API.");
 return;
 }

if (motion == null)
 {
 motion = new Motion();
 motion.TimeBetweenUpdates = TimeSpan.FromMilliseconds(200);
 }

// Try to start the Motion API.
 try
 {
 motion.Start();
 }
 catch (Exception ex)
 {
 MessageBox.Show("The Motion API could not be started.");
 }
 

In the “LoadContent()” method we will load the texture for the Game Ball from the xnb file as shown below.

_gameBall.Texture = Content.Load<Texture2D>("blue_circle_small");

In the “Update()” method we will add the ball motion code. We take the Roll and the Pitch values from the motion sensor API and accordingly update the position of the game ball.

 if (motion.IsDataValid)
 {
 float x = motion.CurrentValue.Attitude.Roll;
 _gameBall.Move(new Vector2((float)(x * ACCELERATION), 0));

float y = motion.CurrentValue.Attitude.Pitch;
 _gameBall.Move(new Vector2(0, (float)(y * ACCELERATION)));

_gameBall.CheckCollision();
 }

And finally we will re-draw the game ball in the “Draw()” method as below.

_gameBall.Draw(_spriteBatch);

After we have followed the above steps the BallBalancerGame.cs file should look like the class shown below.

 /// <summary>
 /// This is the main type for your game
 /// </summary>
 public class BallBalancerGame : Game
 {
 private GraphicsDeviceManager _graphics;
 private SpriteBatch _spriteBatch;
 private Motion motion;
 private GameBall _gameBall;

public static double SCREEN_HEIGHT;
 public static double SCREEN_WIDTH;
 private const float ACCELERATION = 20;

public BallBalancerGame()
 {
 _graphics = new GraphicsDeviceManager(this);
 Content.RootDirectory = "Content";
 }

/// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content. Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 protected override void Initialize()
 {
 // TODO: Add your initialization logic here
 SCREEN_HEIGHT = GraphicsDevice.Viewport.Height;
 SCREEN_WIDTH = GraphicsDevice.Viewport.Width;

_gameBall = new GameBall();

if (!Motion.IsSupported)
 {
 MessageBox.Show("This device doies not support the Motion API.");
 return;
 }

if (motion == null)
 {
 motion = new Motion();
 motion.TimeBetweenUpdates = TimeSpan.FromMilliseconds(200);
 }

// Try to start the Motion API.
 try
 {
 motion.Start();
 }
 catch (Exception ex)
 {
 MessageBox.Show("The Motion API could not be started.");
 }

base.Initialize();
 }

/// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
 // Create a new SpriteBatch, which can be used to draw textures.
 _spriteBatch = new SpriteBatch(GraphicsDevice);
 _gameBall.Texture = Content.Load<Texture2D>("blue_circle_small");
 // TODO: use this.Content to load your game content here
 }

/// <summary>
 /// UnloadContent will be called once per game and is the place to unload
 /// all content.
 /// </summary>
 protected override void UnloadContent()
 {
 // TODO: Unload any non ContentManager content here
 }

/// <summary>
 /// Allows the game to run logic such as updating the world,
 /// checking for collisions, gathering input, and playing audio.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Update(GameTime gameTime)
 {
 // TODO: Add your update logic here
 if (motion.IsDataValid)
 {
 float x = motion.CurrentValue.Attitude.Roll;
 _gameBall.Move(new Vector2((float)(x * ACCELERATION), 0));

float y = motion.CurrentValue.Attitude.Pitch;
 _gameBall.Move(new Vector2(0, (float)(y * ACCELERATION)));

_gameBall.CheckCollision();
 }
 base.Update(gameTime);
 }

/// <summary>
 /// This is called when the game should draw itself.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Draw(GameTime gameTime)
 {
 GraphicsDevice.Clear(Color.CornflowerBlue);
 _spriteBatch.Begin();
 _gameBall.Draw(_spriteBatch);
 // TODO: Add your drawing code here
 _spriteBatch.End();
 base.Draw(gameTime);
 }
 }

Lots of coding, huff, now let’s build the project and make sure there are no build errors. If there are no errors then let’s run the project on windows phone 8 device that supports Motion Sensor.

Figure 11

Privacy Policy for Mind Challenge

This app requires access to your facebook profile and wall. This app doesnt use any of your personal details by publishing them to external sites, retrieval of information, misuse of your data in any form. This app only posts on your wall your recent score and a link to the app in the windows8 app store. The app gives you an option to use facebook and does not by default post to facebook. In case you don’t want to post to facebook you can opt out of this option.

CRM 2011 + Execute workflow from Ribbon Button JavaScript

This post shows how to execute a workflow on click of a ribbon button. Make sure to make the Workflow an On Demand Workflow. Following screenshot shows how to do it:


ExecuteWorkflow = function(entityId, workflowId){

// Soap Request for Executing Workflow
                                        var executeWorkflowSoapRequest = "" +
                    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                    "<soap:Envelope xmlns:soap=\'http://schemas.xmlsoap.org/soap/envelope/\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\'>" +
                    GenerateAuthenticationHeader() +
                    "  <soap:Body>" +
                    "    <Execute xmlns=\'http://schemas.microsoft.com/crm/2007/WebServices\'>" +
                    "      <Request xsi:type=\"ExecuteWorkflowRequest\">" +
                    "        <EntityId>" + entityId + "</EntityId>" +
                    "        <WorkflowId>" + workflowId + "</WorkflowId>" +
                    "      </Request>" +
                    "    </Execute>" +
                    "  </soap:Body>" +
                    "</soap:Envelope>" +
                    "";

// using ajax for the request
                    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
                    xmlHttpRequest.setRequestHeader("SOAPAction",'http://schemas.microsoft.com/crm/2007/WebServices/Execute');
                    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                    xmlHttpRequest.setRequestHeader("Content-Length", executeWorkflowSoapRequest.length);
                    xmlHttpRequest.send(executeWorkflowSoapRequest);

// response of the workflow request
                    var resultXml = xmlHttpRequest.responseXML;
}

function OnClickRibbon()
{
// Get the guid of the workflow created. This can be retrieved from the url of the workflow
// page.
var workflowProcessID = '034EA44C-44D3-4470-B418-10265F5DA8E0';

// Get entity Name
 var entityName = crmForm.ObjectTypeName;

// Get Type Code for entity
var entityID = var etc = Xrm.Page.context.getQueryStringParameters().etc;
// stores the response whether workflow has executed or any error.
var executeWorkflowResponse = '';

executeWorkflowResponse = ExecuteWorkflow(entityID, workflowProcessID);
}

“Only data source using fetch data provider is permitted on this report”

    When we create a FetchXml based report in SSRS or ReportViewer for CRM 2011 Online and then try to import the report in CRM 2011 Online organization it gives the error “Only data source using fetch data provider is permitted on this report”.
The solution for this is to first download an out of the box report and then make your report.

CRM 2011 + updating a Managed Solution without losing data.

 

In CRM many times we have the requirement to remove a plugin or may be a view from an entity or any other customization from an already installed managed solution. The managed solution can reside in your UAT environment or even you product environment. The traditional approach to such a change is make the changes in your unmanaged solution in development environment extract it as managed solution then in the production or UAT environment delete the already installed managed solution and import the new managed solution, with this you lose all your data and have to re- enter the entire data.

    My solution to this problem is simple and described in the following steps:

  1. Make your desired changes in the unmanaged solution in the development environment.
  2. Extract the unmanaged solution as managed solution.
  3. Extract the contents of the managed solution. In the extracted files open the solution.xml file and change the UniqueName of the solution. E.g. if your managed solution has name MySolution then rename it to some name e.g. MySolution_Plugin since I just made a change in plugin class I renamed it so.
    …….<SolutionManifest><UniqueName>MySolution_Plugin</UniqueName>…….
  4. Now import this solution into the production/UAT environment where you want to update the solution file.
  5. So now you will have two solution file in the organization. Delete the previous one and you are done. If you want to get back the same name of the previous solution file that is “MySolution” you can re-import the solution with name changed to “MySolution”.

Hope this post helps a lot of you developers out there. Do let me know if this does not work in any scenario for I have only tested I for plugins and it works. J