Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8913879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:34:16+00:00 2026-06-15T04:34:16+00:00

We are using powershell to create our student users automatically in our Active Directory.

  • 0

We are using powershell to create our student users automatically in our Active Directory. We have everything working except the enable-mailbox. We only give email addresses to our secondary students. So I am trying to have the script read the csv and only enable-mailbox for secondary students. All our secondary schools have campus numbers less than 100, so I tried to have the script use ForEach and then If $_.extensionAttribute1 (column in the csv with the campus number) is less then 100, then it will mail-enable the account. The problem I am having is that only processes the first user and ends the script. I am wanting it to run through each row in the csv. Here is my script.

add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010

Import-CSV C:\scripts\updateuser.csv | ForEach {
    $campus =$_.extensionAttribute1
    If ($campus -lt '100') {
    Enable-Mailbox -Identity $_.sAMAccountName -Database NISDSRV6DB1
    }}

Any help you can provide to make this run through the entire csv would be greatly appreciated.
Thank you in advance for your help.

EDIT…I was messing around with the csv file and I got some interesting results. The only way this script would display anything was if the extensionAttribute1 field was populated with a 1. I am trying to get all users that are less than 100.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:34:18+00:00Added an answer on June 15, 2026 at 4:34 am

    Your ‘extensionAttribute1’ values aren’t being cast as integers properly within the ‘if’ statement. Try this:

    add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
    
    Import-CSV C:\scripts\updateuser.csv | ForEach {
        $campus =$_.extensionAttribute1 -as [Int]
        if ($campus -lt '100'){
            Write-Host $_.sAMAccountName            
            Enable-Mailbox -Identity $_.sAMAccountName -Database NISDSRV6DB1
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about how to add users to AD using powershell, ive
I have a simple powershell script to enable a mailbox in Exchange called test.ps1.
I am trying to create a new web application using PowerShell. I keep getting
I'm using IIS6 using powershell I would like to export a specific virtual directory
I have a file that I set using PowerShell that contains the version number
Using powershell how do you create a content sorce that uses a BDC? Documentation
Is it possible to create a zip archive using PowerShell?
Can anyone tell me how to create a scheduled task using powershell that runs
I am trying to create a empty database in SQL server using powershell and
How do you create a physical folder using DTE and have it added to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.