none
Server is unwilling to process request with New-ADuser, Csv-Import. RRS feed

  • Question

  • #>
    
    
    function Read-OpenFileDialog([string]$WindowTitle, [string]$InitialDirectory, [string]$Filter = "CSV (*.csv)|*.csv", [switch]$AllowMultiSelect)
    {  
       Add-Type -AssemblyName System.Windows.Forms
        $openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
        $openFileDialog.Title = $WindowTitle
        if (![string]::IsNullOrWhiteSpace($InitialDirectory)) { $openFileDialog.InitialDirectory = $InitialDirectory }
        $openFileDialog.Filter = $Filter
        if ($AllowMultiSelect) { $openFileDialog.MultiSelect = $true }
        $openFileDialog.ShowHelp = $true    # Without this line the ShowDialog() function may hang depending on system configuration and running from console vs. ISE.
        $openFileDialog.ShowDialog() > $null
        if ($AllowMultiSelect) { return $openFileDialog.Filenames } else { return $openFileDialog.Filename }
        }
     
        
    $filePath = Read-OpenFileDialog -WindowTitle "Select CSV File" -InitialDirectory 'C:\Users\%USERNAME%' -Filter "Excel Spreadsheet (*.csv)|*.csv"
    if (![string]::IsNullOrEmpty($filePath)) { Write-Host "You selected the file: $filePath" }
    else { "You did not select a file." }
    
    
    Write-Host "This script will grab the path designated in the path column, make sure it is correct."
    Write-Host 'Press Enter to Continue...';
    Read-Host "  "
    
    Import-Module ActiveDirectory 
    
    Import-Csv $filePath | ForEach-Object{
    
    New-ADUser `
    -SamAccountName       $_.sAMAccount`
    -Name                 $_.Name`
    -DisplayName          $_.Name`
    -GivenName            $_.cn`
    -SurName              $_.sn`
    -Description          $_.Description`
    -Department           $_.Department`
    -EmailAddress         $_.PrimaryEmail`
    -Path                 $_.Path`
    -AccountPassword      (ConvertTo-SecureString -AsPlainText $_.Password -Force)`
    -Enabled              $True `
    -PasswordNeverExpires $True `
    -HomeDirectory        $_.HomeShare`
    -HomeDrive            $_.HomeDrive`
    -ScriptPath           $_.LogonScript`
    -PassThru `
    }
    Here is my code, I know there are back ticks, dont hate .. I am getting a "server is unwilling to process request with New-ADuser. Am I needing another variable for the New-ADUser? Everything else works .
    Friday, January 16, 2015 3:26 PM

Answers

All replies