---
title: Using the Microsoft Graph PowerShell SDK: How to Pass Optional Parameters
description: A technique for passing optional parameters to the New-MgUser command.
---

[Spyglass MTG Blog ](https://www.spyglassmtg.com/blog)

# [Using the Microsoft Graph PowerShell SDK: How to Pass Optional Parameters](https://www.spyglassmtg.com/blog/microsoft-graph-powershell-sdk-how-to-pass-optional-parameters)

 Written by [Ian Dicker](https://www.spyglassmtg.com/blog/author/ian-dicker) | May 17, 2023 2:15:00 PM

I was working on a script for a client to solve a typical problem – bulk create of users in Azure AD. I decided to adopt the new Graph PowerShell SDK (see [Microsoft Graph PowerShell SDK overview | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/microsoftgraph/overview?view=graph-powershell-1.0)).

The user information was being driven from a CSV file, which was sparsely populated – meaning that some fields such as Department, Address, or Mobile Phone fields were missing.

The New-MgUser command supports all the properties I wanted to set, such as First, Last, Department, Address etc.

However, there is a major issue with using a parameter such as -Department and specifying an empty string as the value – the request fails with an error message stating that the field value is not valid. So, optional values to the New-MgUser command was just not working for me.

Frustrated, with this lack of functionality, I had to adopt a different approach – Splatting (see [about Splatting - PowerShell | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.3)). Basically, build a Hash table of the parameters you want to pass and then call the Command. For example:

Once you have built the parameter hash table you can then call the command:

The result of the call is an object that describes the user you just created – the most importing thing being the ID (GUID) for the user object in Azure AD.

Hopefully this technique for passing optional parameters to the New-MgUser command will help someone else. If you have any further questions, [please contact us](https://www.spyglassmtg.com/contact-us) today!

[View full post](https://www.spyglassmtg.com/blog/microsoft-graph-powershell-sdk-how-to-pass-optional-parameters)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Ian Dicker"
  },
  "dateModified" : "2023-05-17T14:15:00.362Z",
  "datePublished" : "2023-05-17T14:15:00Z",
  "headline" : "Using the Microsoft Graph PowerShell SDK: How to Pass Optional Parameters",
  "image" : {
    "@type" : "ImageObject",
    "height" : 627,
    "url" : "https://5237880.fs1.hubspotusercontent-na1.net/hubfs/5237880/Untitled%20design%20-%202023-05-11T114547.168.png",
    "width" : 1096
  },
  "mainEntityOfPage" : "https://www.spyglassmtg.com/blog/microsoft-graph-powershell-sdk-how-to-pass-optional-parameters",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Spyglass MTG Blog"
  }
}
```