2017-12-01 12 views
-1

私は現在働いていて作成されたユーザーのパスワードを定義済み独自のフォルダなどを作成します。は、私は、Active Directoryでユーザーを追加するには、「姓」、「姓」と「部署」を入力し、特定のグループに追加するように要求PowerShellのスクリプトにPowerShellのスクリプト

スクリプトを使用して作成したbeeingている間、すべてのユーザーが得るべきであると、デフォルトのパスワードを定義事前にある動作していない唯一のもの。私はパスワードを入力する必要がある別のフィールドを介して動作させることができました。

しかし、ユーザーは、彼が初めてでログインしたらパスワードを変更しているので、私は同じパスワードのすべての時間を入力することを避けるためにしたいと思います。

ありがとうございます!

Clear Host Write-Host "---------------------------------------------------------------" $Vorname = Read-Host "FirstName"
Write-Host "---------------------------------------------------------------" $Nachname = Read-Host "LastName"
Write-Host "---------------------------------------------------------------" $Department = Read-Host "Department"

#Variables 
    $OU = "ou=Sales,dc=contoso,dc=local" 
    $Domain = "contoso.local" 
    $group = "Sales-Alle" 
    $verteiler = "Sales-Mail" 



    $DisplayName = $Vorname + " " + $Nachname 
    $userLogonName = $Vorname + "." + $Nachname 
    $SecurePass = ConvertTo-SecureString -String "Pa$$w0rd" -AsPlainText -Force 

    New-ADUser -Name $Vorname ` 
    -SamAccountName $userLogonName ` 
    -GivenName $Vorname ` 
    -Surname $Nachname ` 
    -DisplayName $DisplayName ` 
    -Department $Department ` 
    -Path $OU ` 
    -AccountPassword $SecurePass ` 
    -Enabled $true ` 
    -UserPrincipalName ($userLogonName + "@" + $Domain) ` 
    -ChangePasswordAtLogon $true 

答えて

0

パスワードの入力をお願いし$securepass = Read-Host -AsSecureString "Enter Password:"を使用することができます。単純にパスワードを生成する場合は、System.Web.Security.Membership class' GeneratePasswordメソッドを使用してパスワードを選択することができます。

#Add the assembly 
Add-Type -AssemblyName System.Web 
#18 characters with a minimum of 4 non alphanumeric 
$unsecurepass = [System.Web.Security.Membership]::GeneratePassword(18,4) 
#convert to a securestring 
$SecurePass = ConvertTo-SecureString -String $unsecurepass -AsPlainText -Force 
#give the initial credential to the person running the script 
Write-Output "User's One Time Password: $unsecurepass" 
#Clear the unsecure password 
Remove-Variable unsecurepass 
#continue with New-ADUser 
関連する問題