Jul 14 2022 10:26 PM
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
Jul 14 2022 11:19 PM
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
Jul 14 2022 11:41 PM
@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
Jul 14 2022 11:50 PM
Command:
$PasswordProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.PasswordProfile' $PasswordProfile.Password = "fGGGGGtyHHHHjj#$5g@@56"
ERROR:
New-Object : Es wurde kein Positionsparameter gefunden, der das Argument "=" akzeptiert.
Jul 14 2022 11:53 PM
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.
Jul 14 2022 11:54 PM
SolutionHere comes the solution.
$PasswordProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.PasswordProfile' ($PasswordProfile.Password = "fGGGGGtyHHHHjj#$5g@@56" )
Many thanks to all
Jul 14 2022 11:54 PM
SolutionHere comes the solution.
$PasswordProfile = New-Object -TypeName 'Microsoft.Open.AzureAD.Model.PasswordProfile' ($PasswordProfile.Password = "fGGGGGtyHHHHjj#$5g@@56" )
Many thanks to all