I could'nt create a new user in Azure with powershell

Occasional Contributor

Hello everybody, 

I hope anybody can help. I wanna creat a new user in my Azure with powershell. The command should be 



# Kennwort erstellen
$PasswordProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.PasswordProfile' 
$PasswordProfile.Password = 'SECRET-PASSWORD'

# Benutzer erstellen
New-AzureADUser -DisplayName "100010-Vorname-Nachname" -PasswordProfile "$PasswordProfile" `
 -UserPrincipalName "email address removed for privacy reasons" -AccountEnabled True`
 -MailNickName "100010-vorname-nachname" -CompanyName "Firma XY" -Department "Abteilung XY"`
-JobTitle "Position XY" -UsageLocation DE



but I get an error like this



New-AzureADUser : Der Parameter "PasswordProfile" kann nicht gebunden werden. Der Wert "class PasswordProfile {
" vom Typ "System.String" kann nicht in den Typ "Microsoft.Open.AzureAD.Model.PasswordProfile" konvertiert werden.
In C:\Scripte\CreateAzureADUser.ps1:18 Zeichen:73
+ ... yName "100010-Vorname-Nachname" -PasswordProfile "$PasswordProfile" `
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-AzureADUser], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Open.AzureAD16.PowerShell.NewUser



$PasswordProfile.Password = 'SECRET-PASSWORD'
$PasswordProfile.Password = "SECRET-PASSWORD"
I've tried it myself with "" or without and it didn't work either.

Where is the mistake? Can andybody help?

best regards


5 Replies


You need to remove the double-qoute from the password 

-PasswordProfile "$PasswordProfile" 

 Make it like this

$PasswordProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.PasswordProfile' 
$PasswordProfile.Password ='fGGGGGtyHHHHjj#$5g@@56'

New-AzureADUser -DisplayName "AZDemoAccount1" -PasswordProfile $PasswordProfile -UserPrincipalName "email address removed for privacy reasons" -MailNickName "AZDemoAccount1" -CompanyName "MyCompany" -Department "Abteilung XY" -JobTitle "Position XY" -UsageLocation DE -AccountEnabled $true

@farismalaeb Thx first of all.

 Here ist the result of your solution.

$PasswordProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.PasswordProfile' $PasswordProfile.Password ='fGGGGGtyHHHHjj#$5g@@56' 

New-AzureADUser -DisplayName "100010-Vorname-Nachname" -PasswordProfile $PasswordProfile -UserPrincipalName "email address removed for privacy reasons"`
 -MailNickName "100010-Vorname-Nachname" -CompanyName "Firma XY" -Department "Abteilung XY" -JobTitle "Position XY" -UsageLocation DE -AccountEnabled $true 
Cmdlet Get-Credential an der Befehlspipelineposition 1
Geben Sie Werte für die folgenden Parameter an:

Account               Environment TenantId                             TenantDomain   AccountType
-------               ----------- --------                             ------------   -----------
email address removed for privacy reasons AzureCloud  xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx User       
New-Object : Es wurde kein Positionsparameter gefunden, der das Argument "=fGGGGGtyHHHHjj#$5g@@56" akzeptiert.
In Zeile:5 Zeichen:20
+ ... rdProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.Passwo ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-Object], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

ExtensionProperty              : {[odata.metadata,$metadata#directoryObjects/@Element], [odata.type, 
                                 Microsoft.DirectoryServices.User], [createdDateTime, ], [employeeId, ]...}
DeletionTimestamp              : 
ObjectId                       : 123456-12345-1234-12345-xxxxxxxxx
ObjectType                     : User
AccountEnabled                 : True
AgeGroup                       : 
AssignedLicenses               : {}
AssignedPlans                  : {}
City                           : 
CompanyName                    : Firma XY
ConsentProvidedForMinor        : 
Country                        : 
CreationType                   : 
Department                     : Abteilung XY
DirSyncEnabled                 : 
DisplayName                    : 100010-Vorname-Nachname
FacsimileTelephoneNumber       : 
GivenName                      : 
IsCompromised                  : 
ImmutableId                    : 
JobTitle                       : Position XY
LastDirSyncTime                : 
LegalAgeGroupClassification    : 
Mail                           : 
MailNickName                   : 100010-Vorname-Nachname
Mobile                         : 
OnPremisesSecurityIdentifier   : 
OtherMails                     : {}
PasswordPolicies               : 
PasswordProfile                : class PasswordProfile {
                                   ForceChangePasswordNextLogin: True
                                   EnforceChangePasswordPolicy: False
PhysicalDeliveryOfficeName     : 
PostalCode                     : 

but a new user was created

2022-07-15 08_38_54-Aktive Benutzer - Microsoft 365 admin center.png 





$PasswordProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.PasswordProfile' $PasswordProfile.Password = "fGGGGGtyHHHHjj#$5g@@56"



New-Object : Es wurde kein Positionsparameter gefunden, der das Argument "=" akzeptiert.


Correct me if I am wrong, But I see you type both lines in one line.

Make sure that they are in a separate line


$PasswordProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.PasswordProfile'

$PasswordProfile.Password ='Norm@lPassw0rd'

Also make sure that the password fit with your organization policy.


best response confirmed by MSpang (Occasional Contributor)

@MSpang @farismalaeb 

Here comes the solution.

$PasswordProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.PasswordProfile' ($PasswordProfile.Password = "fGGGGGtyHHHHjj#$5g@@56" )


Many thanks to all