none
Powershell: New-ADUser : Die Syntax des Objektnamens ist ungültig RRS feed

  • Frage

  • Hallo,

    ich habe seit Gestern angefangen mich etwas mit Powershell zu beschäftigen und möchte ein Skript bauen, das User in der AD anlegt. Nun bin ich seit einigen Stunden dabei diesen Fehler zu lösen.

    New-ADUser : Die Syntax des Objektnamens ist ungültig
    In C:\Users\Administrator\Desktop\Powershell\2. Form darstellen\Form.ps1:110 Zeichen:13
    +             New-ADUser -Name $objTextBox3 -GivenName $objTextBox1 -Su ...
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (CN=System.Windo... Items.Count: 3:String) [New-ADUser], ADException
        + FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADUser

    Bin aber bisher leider am Ende und weiß nicht mehr was ich versuchen kann. Vielleicht kann mir einer von euch bei dem Problem helfen.

    Danke schon einmal in voraus!

    # Alle im Forest gefundenen Domänen abrufen
    $AvailableDomains=(get-adforest).domains
    # Wenn keine Domäne gefunden wird abbrechen
    if ($AvailableDomains.count -lt 1) {throw "Keine Domäne zur Verwaltung gefunden"}
    else {
    
    
    #OU's werden abgerufen
    
    $AvailableOU = Get-ADObject -Filter {ObjectClass -eq 'organizationalunit'}
    
    
    #Die ersten beiden Zeilen oeffnen die Form
    
    [void] [System.Reflection.Assembly]::LoadWi
    [void] [System.Reflection.Assembly]::LoadWi
    
    
    #Die nächste Zeile erstellt aus der Formsbibliothek das Fensterobje.
    
    $objForm = New-Object System.Windows.Forms.Form
    
    
    #Die Titelzeile wird beschriftet
    
    $objForm.Text = "AD PowerManagmant"
    
    
    #Die groesse des Fensters wird bestimmt. 250x600 Pixel
    
    $objForm.Size = New-Object System.Drawing.Size(250,350)
    
    
    #Position des Fensters wird mittig angegeben
    
    $objForm.StartPosition = "CenterScreen"
    
    #Ein Lable wird dem Fenster hinzugefügt
    
    $objLabel = New-Object System.Windows.Forms.Label
    $objLabel.Location = New-Object System.Drawing.Size(10,20)
    $objLabel.Size = New-Object System.Drawing.Size(100,20)
    $objLabel.Text = "Domain"
    $objLabel.Name = "Domain"
    $objForm.Controls.Add($objLabel)
    
    
    #Ein Lable2 wird dem Fenster hinzugefügt
    
    $objLabel2 = New-Object System.Windows.Forms.Label
    $objLabel2.Location = New-Object System.Drawing.Size(10,60)
    $objLabel2.Size = New-Object System.Drawing.Size(100,20)
    $objLabel2.Text = "OU"
    $objLabel2.Name = "OU"
    $objForm.Controls.Add($objLabel2)
    
    
    #Ein Lable3 wird dem Fenster hinzugefügt
    
    $objLabel3 = New-Object System.Windows.Forms.Label
    $objLabel3.Location = New-Object System.Drawing.Size(10,100)
    $objLabel3.Size = New-Object System.Drawing.Size(100,20)
    $objLabel3.Text = "Vorname"
    $objLabel3.Name = "Vorname"
    $objForm.Controls.Add($objLabel3)
    
    
    #Ein Lable4 wird dem Fenster hinzugefügt
    
    $objLabel4 = New-Object System.Windows.Forms.Label
    $objLabel4.Location = New-Object System.Drawing.Size(10,140)
    $objLabel4.Size = New-Object System.Drawing.Size(100,20)
    $objLabel4.Text = "Nachname"
    $objLabel4.Name = "Nachname"
    $objForm.Controls.Add($objLabel4)
    
    
    #Ein Lable5 wird dem Fenster hinzugefügt
    
    $objLabel5 = New-Object System.Windows.Forms.Label
    $objLabel5.Location = New-Object System.Drawing.Size(10,180)
    $objLabel5.Size = New-Object System.Drawing.Size(100,20)
    $objLabel5.Text = "Anzeigename"
    $objLabel5.Name = "Anzeigename"
    $objForm.Controls.Add($objLabel5)
    
    
    #Ein Lable6 wird dem Fenster hinzugefügt
    
    $objLabel6 = New-Object System.Windows.Forms.Label
    $objLabel6.Location = New-Object System.Drawing.Size(10,220)
    $objLabel6.Size = New-Object System.Drawing.Size(100,20)
    $objLabel6.Text = "Passwort"
    $objLabel6.Name = "Passwort"
    $objForm.Controls.Add($objLabel6)
    
    
    
    #Der Benutzer wird der AD hinzugefügt
    
    $user = {
                
                $password = $objTextBox4 | ConvertTo-SecureString -AsPlainText -Force
                New-ADUser -Name $objTextBox3 -GivenName $objTextBox1 -Surname $objTextBox2 -Path $objCombobox2 -AccountPassword $password -ChangePasswordAtLogon $True -Enabled $True
    
    
            }
    
    
    #Ein Button wird hinzugefügt "OK"
    
    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Size(10,260)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = "OK"
    $OKButton.Name = "OK"
    $OKButton.Add_Click($user)
    $objForm.Controls.Add($OKButton)
    
    
    #Eine Combobox1 wird dem Fenster hinzugefügt
    
    $objCombobox = New-Object System.Windows.Forms.ComboBox
    $objCombobox.Location = New-Object System.Drawing.Size(120,20)
    $objCombobox.Size = New-Object System.Drawing.Size(100,20)#
    $AvailableDomains | foreach {[void] $objCombobox.Items.Add("$_")}
    $objForm.Controls.Add($objCombobox)
    
    
    #Eine Combobox2 wird dem Fenster hinzugefügt
    
    $objCombobox2 = New-Object System.Windows.Forms.ComboBox
    $objCombobox2.Location = New-Object System.Drawing.Size(120,60)
    $objCombobox2.Size = New-Object System.Drawing.Size(100,20)
    $AvailableOU | foreach {[void] $objCombobox2.Items.Add("$_")}
    $objForm.Controls.Add($objCombobox2)
    
    
    #Ein Textfeld1 wird dem Fenster hinzugefügt
    
    $objTextBox = New-Object System.Windows.Forms.TextBox
    $objTextBox.Location = New-Object System.Drawing.Size(120,100)
    $objTextBox.Size = New-Object System.Drawing.Size(100,20)
    $objForm.Controls.Add($objTextBox)
    
    
    #Ein Textfeld2 wird dem Fenster hinzugefügt
    
    $objTextBox2 = New-Object System.Windows.Forms.TextBox
    $objTextBox2.Location = New-Object System.Drawing.Size(120,140)
    $objTextBox2.Size = New-Object System.Drawing.Size(100,20)
    $objForm.Controls.Add($objTextBox2)
    
    
    #Ein Textfeld3 wird dem Fenster hinzugefügt
    
    $objTextBox3 = New-Object System.Windows.Forms.TextBox
    $objTextBox3.Location = New-Object System.Drawing.Size(120,180)
    $objTextBox3.Size = New-Object System.Drawing.Size(100,20)
    $objForm.Controls.Add($objTextBox3)
    
    
    #Ein Textfeld4 wird dem Fenster hinzugefügt
    
    $objTextBox4 = New-Object System.Windows.Forms.TextBox
    $objTextBox4.Location = New-Object System.Drawing.Size(120,220)
    $objTextBox4.Size = New-Object System.Drawing.Size(100,20)
    $objForm.Controls.Add($objTextBox4)
    
    #Durch die nächste Zeile wird das Fenster dargestellt
    
    [void] $objForm.ShowDialog()
    
    }

    Dienstag, 30. August 2016 09:42

Antworten

  • Hallo Domeit,

    versuch es mal hiermit:

    #Der Benutzer wird der AD hinzugefügt
    
    $user = {
                
                $password = $objTextBox4.Text | ConvertTo-SecureString -AsPlainText -Force
                New-ADUser -Name $objTextBox3.Text -GivenName $objTextBox1.Text -Surname $objTextBox2.Text -Path $objCombobox2.Text -AccountPassword $password -ChangePasswordAtLogon $True -Enabled $True
    
    
            }

    Hier heißt das erstellte Form $objTextBox, beim User anlegen arbeitest Du aber mit $objTextBox1 - die gibt es gar nicht ;)
    #Ein Textfeld1 wird dem Fenster hinzugefügt
    
    $objTextBox = New-Object System.Windows.Forms.TextBox
    $objTextBox.Location = New-Object System.Drawing.Size(120,100)
    $objTextBox.Size = New-Object System.Drawing.Size(100,20)
    $objForm.Controls.Add($objTextBox)

    Was mir noch aufgefallen ist, bei New-ADUser übergibst Du den Parameter -SamAccountName, also den Usernamen des neuen Benutzerobjekts, nicht. Das könnte Dir auch noch auf die Füße fallen.


    Freundliche Grüße
    Sandro

    MCSA: Windows Server 2012 in spe ;)
    Fachinformatiker Fachrichtung Systemintegration (IHK, 07/2013)

    XING: Zum Profil
    LinkedIn: Zum Profil
    Facebook: Zum Profil




    • Bearbeitet SandroReiter Dienstag, 30. August 2016 10:23
    • Als Antwort vorgeschlagen SandroReiter Dienstag, 30. August 2016 10:27
    • Als Antwort markiert Domeit Dienstag, 30. August 2016 12:01
    Dienstag, 30. August 2016 10:17

Alle Antworten

  • Hallo Domeit,

    versuch es mal hiermit:

    #Der Benutzer wird der AD hinzugefügt
    
    $user = {
                
                $password = $objTextBox4.Text | ConvertTo-SecureString -AsPlainText -Force
                New-ADUser -Name $objTextBox3.Text -GivenName $objTextBox1.Text -Surname $objTextBox2.Text -Path $objCombobox2.Text -AccountPassword $password -ChangePasswordAtLogon $True -Enabled $True
    
    
            }

    Hier heißt das erstellte Form $objTextBox, beim User anlegen arbeitest Du aber mit $objTextBox1 - die gibt es gar nicht ;)
    #Ein Textfeld1 wird dem Fenster hinzugefügt
    
    $objTextBox = New-Object System.Windows.Forms.TextBox
    $objTextBox.Location = New-Object System.Drawing.Size(120,100)
    $objTextBox.Size = New-Object System.Drawing.Size(100,20)
    $objForm.Controls.Add($objTextBox)

    Was mir noch aufgefallen ist, bei New-ADUser übergibst Du den Parameter -SamAccountName, also den Usernamen des neuen Benutzerobjekts, nicht. Das könnte Dir auch noch auf die Füße fallen.


    Freundliche Grüße
    Sandro

    MCSA: Windows Server 2012 in spe ;)
    Fachinformatiker Fachrichtung Systemintegration (IHK, 07/2013)

    XING: Zum Profil
    LinkedIn: Zum Profil
    Facebook: Zum Profil




    • Bearbeitet SandroReiter Dienstag, 30. August 2016 10:23
    • Als Antwort vorgeschlagen SandroReiter Dienstag, 30. August 2016 10:27
    • Als Antwort markiert Domeit Dienstag, 30. August 2016 12:01
    Dienstag, 30. August 2016 10:17
  • danke! funktioniert jetzt alles :)
    Dienstag, 30. August 2016 10:24
  • Sehr gern, viel Spaß weiterhin mit der PowerShell ;)

    Markiere doch bitte noch den hilfreichen Beitrag als Antwort :)


    Freundliche Grüße
    Sandro

    MCSA: Windows Server 2012 in spe ;)
    Fachinformatiker Fachrichtung Systemintegration (IHK, 07/2013)

    XING: Zum Profil
    LinkedIn: Zum Profil
    Facebook: Zum Profil

    Dienstag, 30. August 2016 10:28