Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Cmdlet für Domainjoin in Unter-OU

$
0
0

Hallo Zusammen,

ich habe folgendes Problem und konnte bis jetzt keine Lösung finden:

in den folgenden Zeilen frage ich den zukünftigen PC Namen ab um ihn mit diesem dann der Domäne hinzuzufügen.

An sich funktioniert das Ganze, solange ich ihn nicht in eine "Unter-OU" hinzufügen will. Dann spuckt er nämlich einen Fehler aus. Ich weiß, ich müsste jetzt das Ganze Zeile für Zeile ausführen, dass ich euch den genauen Fehler geben kann (das werde ich auf jeden Fall machen, falls nicht jmd direkt das Problem erkennt). Ich habe jetzt nur einen Auszug aus dem Script genommen in dem man das einbinden der OUs sieht...die fehlenden Variablen beim domainjoin werden ganz am Anfang des Scripts mitgegeben und das funktioniert auch. Es geht tatsächlich nur um die Angabe einer Unter-OU.

-OUPath "$OUPath,DC=domain,DC=tld"


Set-ItemProperty $RunOnceKey "NextRun" ('C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -executionPolicy Unrestricted -File ' + "C:\Script.ps1") 

$WSName = Read-Host "Wie soll der PC Name heißen?"
    $OUMenue = Read-Host -Prompt "In welche OU soll der Rechner hinzugefügt werden
            `n 1.PCs            
            `n 2.PCs | UnterOU1
            `n 3.PCs | UnterOU2
            `n 4.PCs | UnterOU2 | UnterOU3
            `n 5.PCs | UnterOU3
            `n 6.PCs | UnterOU4
            `n 7.PCs | UnterOU5
            `n 8.PCs | UnterOU6

            `n Wähle eine Nummer"

    switch($OUMenue){
            
            1{$OU = "PCs"
            $OUPath = "OU=PCs"
            write-host "$WSName wurde zur OU $OU hinzugefügt" -ForegroundColor green
            }
            2{$OU1 = "PCs | UnterOU1"
            $OUPath = "OU=UnterOU1,OU=PCs"
            write-host "$WSName wurde zur OU $OU hinzugefügt" -ForegroundColor green
            }
            3{$OU1 = "PCs | UnterOU2"
            $OUPath = "OU=UnterOU2,OU=PCs"
            write-host "$WSName wurde zur OU $OU hinzugefügt" -ForegroundColor green
            }
            4{$OU1 = "PCs | UnterOU2 -> UnterOU3"
            $OUPath = "OU=UnterOU3,OU=UnterOU2,OU=PCs"
            write-host "$WSName wird zur OU $OU hinzugefügt" -ForegroundColor green
            }
            5{$OU1 = "PCs | UnterOU4"
            $OUPath = "OU=UnterOU4,OU=PCs"
            write-host "$WSName wird zur OU $OU hinzugefügt" -ForegroundColor green
            }
            6{$OU1 = "PCs | UnterOU5"
            $OUPath = "OU=UnterOU5,OU=PCs"
            write-host "$WSName wird zur OU $OU hinzugefügt" -ForegroundColor green
            }
            7{$OU1 = "PCs | UnterOU6"
            $OUPath = "OU=UnterOU6,OU=PCs"
            write-host "$WSName wird zur OU $OU hinzugefügt" -ForegroundColor green
            }
            8{$OU1 = "PCs | UnterOU7"
            $OUPath = "OU=UnterOU7,OU=PCs"
            write-host "$WSName wird zur OU $OU hinzugefügt" -ForegroundColor green
            }
                    }

    New-Item -Path C:\ -Name OUPath -ItemType Directory | Out-Null
    $OUPath | export-clixml -path "C:\OUPath\OUPath"
    Rename-Computer -NewName $WSName -Force
    Restart-Computer -Force

#nach Reboot

$OUPath = import-clixml -path "C:\OUPath\OUPath"
Set-NetFirewallProfile -Profile Domain,Private,Public -Enabled False
    New-ItemProperty -Type DWord -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender" -Name DisableAntiSpyware -Value "1"

Add-computer -DomainCredential $credjoin -DomainName $Domain -OUPath "$OUPath,DC=domain,DC=tld"        
    Restart-Computer -force

Ich freue mich auf eure Hilfe!

Vielen Dank im Voraus.

Grüße Kice88



Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>