Forum Discussion
MSpang
Jul 15, 2022Copper Contributor
I could'nt create a new user in Azure with powershell
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 {
Password: SECRET-PASSWORD
ForceChangePasswordNextLogin:
EnforceChangePasswordPolicy:
}
" 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
Mario
Here comes the solution.
$PasswordProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.PasswordProfile' ($PasswordProfile.Password = "fGGGGGtyHHHHjj#$5g@@56" )Many thanks to all
5 Replies
Sort By
- farismalaebSteel Contributor
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
- MSpangCopper Contributor
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 palettecad.net 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, https://graph.windows.net/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/$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 { Password: ForceChangePasswordNextLogin: True EnforceChangePasswordPolicy: False } PhysicalDeliveryOfficeName : PostalCode :
but a new user was created