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 8922979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:59:11+00:00 2026-06-15T06:59:11+00:00

I got the following code (working): #Import File $Users = Import-Csv C:\Users\Administrator\Desktop\userImport\users.csv # Setting

  • 0

I got the following code (working):

   #Import File
$Users = Import-Csv C:\Users\Administrator\Desktop\userImport\users.csv

# Setting data
$compname = hostname
$computer = [ADSI]"WinNT://$compname" 
$userGroup = [ADSI]"WinNT://./Users,Group"

# Loop to add all users
$Users | %  { 

    # Create user itself
    $createUser = $computer.Create("User",$_.userid)

    # Set password (print1!)
    $createUser.SetPassword($_.password)
    $createUser.SetInfo()

    # Create extra data
    $createUser.Description = "Import via powershell"
    $createUser.FullName = $_.'full name'
    $createUser.SetInfo()

    # Set standard flags (Password expire / Password change / Account disabled)
    $createUser.UserFlags = 64 + 65536 # ADS_UF_PASSWD_CANT_CHANGE + ADS_UF_DONT_EXPIRE_PASSWD
    $createUser.SetInfo()

    # Adduser to standard user group ("SERVER02\Users")
    $userGroup.Add($createUser.Path)

    # Show that user X as been added
    $username = $_.'full name'
    echo "User  $username added"
}

But how is possible to build an check if the user already exists?
I can not really find anything on the web 😡

  • 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-15T06:59:13+00:00Added an answer on June 15, 2026 at 6:59 am

    You can try this:

       #Import File
    $Users = Import-Csv C:\Users\Administrator\Desktop\userImport\users.csv
    
    # Setting data
    $compname = hostname
    $computer = [ADSI]"WinNT://$compname" 
    $userGroup = [ADSI]"WinNT://./Users,Group"
    
    $localUsers = $computer.Children | where {$_.SchemaClassName -eq 'user'}  |  % {$_.name[0].ToString()}
    
    # Loop to add all users
    $Users | %  { 
    
        if($localUsers -NotContains $_.userID)
        {
          ... do your job here....
        }
        else
        {
          write-host "User $($_.userID) already exists"
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following snippet of code and its all working, and bringing in
I got the following code: char buffer[2047]; int charsRead; do { if(fscanf(file, %2047[^\n]%n%*c, buffer,
I have got following code witch are sending xml file on HTTP protocol and
Working through Pro ASP.NET MVC book and I got the following code snippet that
I've got the following code that someone working on MSVC has given to me:
For whatever reason, the following code isn't working: #import <Foundation/Foundation.h> @interface UIView (FindUIViewControllerParent) -
I've got the following code that I can't seem to get working: function drawTable($result)
I got following code in an XHTML-document and every browser saysit is malformed :(
I got following code from net and it looks everything is proper but i'm
I've got following code in my AsyncTask. The only thing I want the AsyncTask

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.