2016-05-10 3 views
1

私はPowerShellの新機能です。ターミネーターが見つからず、PowerShellで欠落している可能性があります

次のPowerShellスクリプトがあります。

$FieryChasm = { 

    Clear-Host 

    Write-Host "`n This script is for dropping user accounts from the Active Directory.`n`n`n It will :`n`n - Disable the AD account`n - Reset the AD password`n - Move the account to the Disabled OU`n - Set the expiry date on the account to yesterday's date`n - Remove all @ groups`n- Hide the user from the email exchange`n`n`n`n Input the UserID`n" 

    $UserID = Read-Host -Prompt ' ' 
    Clear-Host 

    $title = "`n You input '$UserID'" 
    $message = "`n`n Are you certain you want to process this UserID as a leaver?`n`n`n`n" 

    $yes = New-Object System.Management.Automation.Host.ChoiceDescription " &Yes", ` 
    "Yes, process this userID as a leaver.`n" 

    $no = New-Object System.Management.Automation.Host.ChoiceDescription " &No", ` 
    "No, take me back a step so I can input the UserID again.`n" 

    $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) 

    $result = $host.ui.PromptForChoice($title, $message, $options, 1) 

    Clear-Host 

    switch ($result) 
    { 
     0 { 
     Write-Host "`n Disabling account...`n" 
      Disable-ADAccount -Identity $UserID 

      Write-Host "`n Moving to OU 'Disabled Accounts'...`n" 
      Move-ADObject -Identity $UserID -TargetPath "OU=Disabled Accounts,DC=my-company,DC=co,DC=uk" 

      Write-Host "`n Resetting password...`n" 
      $YouShallNotPass = (Get-Random -input "Da$her","Danc%r","Pr$ncer","V!xen","C$met","Cup!d","Donn%r","Bl!tzen") + (Get-Random -Minimum 1000 -Maximum 999999) + (Get-Random -input "Da$her","Danc%r","Pr$ncer","V!xen","C$met","Cup!d","Donn%r","Bl!tzen") 
      Set-ADAccountPassword -Reset -NewPassword $YouShallNotPass –Identity $UserID 

      Write-Host "`n Setting expiry date...`n" 
      $Yesterday = (Get-Date).AddDays(-1).ToString('dd/MM/yyyy') 
      Set-ADAccountExpiration $UserID -DateTime $Yesterday 

      Write-Host "`n Removing AD groups...`n" 
      Get-ADuser $UserID -property MemberOf | % {$_.MemberOf | Get-ADGroup | select Name | sort name} | clip 
      Get-ADGroup -Filter 'name -like "@*"' | Remove-ADGroup -identity $UserID 

      Write-Host "`n Hiding user from Exchange...`n" 
      Set-Mailbox -Identity DOMAIN\$UserID -HiddenFromAddressListsEnabled $true 

      Write-Host "`n Completed.`n`n $UserID has been processed as a leaver.`n`n`n Press any key to go back to the fiery chasm from whence you came ..."        

      $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") 

     } 

     1 { 
     Write-Host "`n You selected No.`n`n User was NOT set as a leaver.`n`n`n Press any key to go back to the fiery chasm from whence you came ..." 
     } 
    } 

    .$FieryChasm 
} 

と、私は次のエラーを取得しています...

At C:\Users\user\Desktop\LeaverScript.ps1:64 char:148 
+ ... ce you came ..." 
+     ~ 
The string is missing the terminator: ". 
At C:\Users\user\Desktop\LeaverScript.ps1:34 char:8 
+      0 { 
+      ~ 
Missing closing '}' in statement block. 
At C:\Users\user\Desktop\LeaverScript.ps1:33 char:5 
+     { 
+     ~ 
Missing closing '}' in statement block. 
At C:\Users\user\Desktop\LeaverScript.ps1:1 char:15 
+ $FieryChasm = { 
+    ~ 
Missing closing '}' in statement block. 
    + CategoryInfo   : ParserError: (:) [], ParseException 
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString 

誰かが理由を説明し、再び同じ過ちをしていない私にいくつかのヒントを与えてもらえますか?

ありがとうございます。

+0

私はエラーを再現できません。 – vonPryz

+0

奇妙な。それが助けになるならば、私は窓7にあり、$ PSVersionTable.PSVersionの出力はメジャー3、マイナー0、ビルド-1、リビジョン-1です。 – haze1434

+0

$ PSVersionTableはPSVersionを3.0、ビルド6.2.9200.16481 – haze1434

答えて

0

ああ、それを得ました!

オンラインで37、これはこれでした。

Set-ADAccountPassword -Reset -NewPassword $YouShallNotPass -Identity $UserID 

'Identity'の前にダッシュが間違ったUnicode文字だった。私はそれを置き換え、エラーは消え去った:

関連する問題