Importing a multiple users Trough Powershell Scripts

Hi All
Am completely new to this technology am having a source code for “Adding a single user to a SG Group” similarly I need to Add a multiple users through PowerShell scripts.
Set-Variable
-Name
GROUPNAME
-Value
"<My Group>"
-Option
Constant
Set-Variable -Name
USERNAME
-Value "<My User>"
-Option Constant
Set-Variable -Name
URI
-Value "http://localhost:5725/resourcemanagementservice"
-Option Constant
Function GetSingleResource
Param($Filter)
End
$exportResource
= export-fimconfig
-uri $URI
`
–onlyBaseResources
`
-customconfig ("$Filter")`
-ErrorVariable Err
`
-ErrorAction SilentlyContinue
If($Err){Throw
$Err}
If($exportResource
-eq $null) {Throw
"Resource not found: $Filter"}
If(@($exportResource).Count
-ne 1) {Throw
"More than one resource found: $Filter"}
$exportResource
If(@(Get-PSSnapin
| Where-Object {$_.Name
-eq "FIMAutomation"} ).count
-eq 0) {Add-PSSnapin
FIMAutomation}
Clear-Host
$ProgressPreference
= "SilentlyContinue"
$ProgressPreference
= "Continue"
Write-Progress -Activity
"Retrieving group object"
`
-Status "Please wait..."
`
-CurrentOperation
"Processing step 1 of 3"
$ProgressPreference
= "SilentlyContinue"
$groupObject
= GetSingleResource
-Filter "/Group[DisplayName='$GROUPNAME']"
$ProgressPreference
= "Continue"
Write-Progress -Activity
"Retrieving user object"
`
-Status "Please wait..."
`
-CurrentOperation
"Processing step 2 of 3"
$ProgressPreference
= "SilentlyContinue"
$userObject
= GetSingleResource
-Filter "/Person[DisplayName='$USERNAME']"
$importChange
= New-Object
Microsoft.ResourceManagement.Automation.ObjectModel.ImportChange
$importChange.Operation
= 0
$importChange.AttributeName
= "ExplicitMember"
$importChange.AttributeValue
= $userObject.ResourceManagementObject.ObjectIdentifier
$importChange.FullyResolved
= 0
$importChange.Locale
= "Invariant"
$importObject
= New-Object
Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
$importObject.ObjectType
= "Group"
$importObject.TargetObjectIdentifier
= $groupObject.ResourceManagementObject.ObjectIdentifier
$importObject.SourceObjectIdentifier
= $groupObject.ResourceManagementObject.ObjectIdentifier
$importObject.State
= 1
$ImportObject.Changes
= (,$ImportChange)
$ProgressPreference
= "Continue"
Write-Progress -Activity
"Adding user to group"
`
-Status "Please wait..."
`
-CurrentOperation
"Processing step 3 of 3"
$ProgressPreference
= "SilentlyContinue"
$importObject
| Import-FIMConfig
-Uri $URI
-ErrorVariable
Err -ErrorAction
SilentlyContinue
| Out-Null
If($Err){Throw
$Err}
Write-Host "Command completed successfully"
Trap
Write-Host $_.Exception.Message
-foregroundcolor
white
-backgroundcolor
darkred
Write-Host $_.Exception.GetType().FullName
-foregroundcolor
white
-backgroundcolor
darkred
Write-Host "`n"
Exit 1
Regards:
Rajesh.k

What is your question?  Also, please refrain from dumping ~100 lines of code.  If you need help with a specific portion, please post just that and be clear with your question.
Mike Crowley | MVP
My Blog --
Planet Technologies

Similar Messages

  • Creating multiple user tables using script

    hi
    my requirement is i want to create multiple tables by running script . is it possible .how do i do that can any one suggest me and send sample code to solve this task.
    (i have to create 100 userTables it is very difficult to create using code or from B1 that is my requirement )and i think some good solution is there for my problem and inserting the tables into B1 by running script.

    Hi Om,
    Take a look at the SDK help files, or even better, the examples provided with the SDK, they give you a good example how to create a usertable.
    Tried that, you could programm a loop wich creates your usertables, or a function that progresses a input file containing all your usertables.
    <b>Pseudo code loop (C#)</b>
    for(int i = 1; i <=100; i++)
      /* Call you your function that creates a usertable with the given name */
      CreateUserTable("TBL_" + i.ToString());
    Hope it helps,
    Rowdy

  • Current logged on user using Powershell script

    Hi,
    i found a vb script which works fine and gives me desired output however i am looking to get this converted to powershell, so that i can add this to an existing shell script
    Purpose : the shell script should display/Echo currently logged on user, by reading the wmi
    Below is the vb script which i found, also i dont want its first line because i will be running the script locally on the computer with admin rights
    strComputer = "atl-ws-01"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'explorer.exe'")
    If colItems.Count = 0 Then
    Wscript.Echo "No one is logged on to the computer."
    Else
    For Each objProcess in colItems
    objProcess.GetOwner strUser, strDomain
    Wscript.Echo strDomain & "\" & strUser
    Next
    End If--------RegardsTanoj
    OSLM ENGINEER - SCCM 2007 & 2012

    Thank you for the reply
    yes mjolinor you caught me, i am working with sccm 2012 trying to create a universal script which will work flawlessly on VM, windows 8, Windows 7 etc ....
    so which one you think is good to fullfill my need,
    Get-WmiObject
    -Class win32_process
    -filter "Name = 'explorer.exe'" -computer VMNAME    ?
     also it will be great help if you could help me get the complete script wich includes the above line,
    i get following error when executing the above command
    Regards
    Tanoj

  • Multiple Users/Logging In Problem

    Using Multiple Users I added a second user to our iMac DV400 (blueberry, slot loading) running OS9.2.1. The problem: now we can only log on to the second user's desktop and can't access the primary user's desktop. Since the second user is set up with limited user privileges, we can't access the system programs; most importantly, the Multiple Users program so that we can revert this problem by deleting the second user from the system. Can anyone offer some help?
    Thanks

    Welcome to Apple Discussions pd,
    Start from your Mac OS installer CD (insert it and hold the c key, release the key when you see the "Welome To Macintosh" message)
    Open your hard drive and locate the System folder. Open that and locate the Preferences folder. From that folder, delete the three preference files and one folder with "Multi User" in their names.
    Restart as normal and empty the trash. You will have to re-create the user accounts.

  • Powershell script for security groups and users for multiple share folders

    Hi scripting team,
    I need your help with powershell script for the below queries 
    1. List out the security groups for more than one server share path and output it to a file ( csv ) 
    For eg.
    If the are are two share paths 
    \\servername\foldermain\folder1
    \\servername\foldermain\folder2
    So I needs the list of security groups for each share path
    And the output needs to be under each any every path.
    2. Grab the users belongs to main security groups and it nested groups for more than one security group and listed the users under each and every group. No need to display nested groups. Just users belongs to main group and users under nested.
    Your teams help is much appreciated 
    Thank you.
    Thilochana kumararatne

    Hi Braham,
    Thanks for your quick reply.
    Are we able to do this on two stage method
    1. grab the security groups from the share paths
    if can grab the share path from a separate txt file than copying it to the <your path> location
    so i can modify the txt file
    once run the script
    if can the output like below to a CSV file
    \\servername\foldermain\folder1group 1group 2group 3\\servername\foldermain\folder2group 1group 2group 3then i know which groups belongs to which share paththen i can remove the duplicate groups and keep the common groups to grab the users belongs to itso with the second script same as the first copy the security groups to a txt file and the out put as below.what I needs is the users full name and the samaccount name ( user id )group 1user1user2user3
    group 2user1user2user3looking forward your help on thisThank you.Thilo

  • Exchange PowerShell script to get mailbox properties of user from a CSV file

    Hi Team,
    I've a CSV file with alias of numerous users and I want to get their mailbox sizes and other properties. These users are dispersed in various databases of same Exchange organization.
    Need a Powershell Script, Any help?
    Muhammad Nadeem Ahmed Sr System Support Engineer Premier Systems (Pvt) Ltd T. +9221-2429051 Ext-226 F. +9221-2428777 M. +92300-8262627 Web. www.premier.com.pk

    You can use this and modify it to what you need. Output to a file (IE: Export-CSV "path to file"
    If you need more specifics let me know. This one is for one user at a time but can be used to read a CSV file.
    # Notifies the user a remote session needs to be started
    Write-Host "Get a users mailbox size" -fore yellow -back red;
    Write-Host "Please wait while a remote session started" -fore red -back yellow;
    # Import a remote session with exchange
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchangeservername/Powershell/ -Authentication Kerberos
    Import-PSSession $Session
    Do {
    # Prompts user for a name
    $name = Read-Host "Enter a username"
    # Get the mailbox statistics for that user
    Get-MailboxStatistics $name | fl totalitemsize, storagelimitstatus, totaldeleteditemsize | out-default
    # Give the user a choice to test another or EXIT
    $Output = Read-Host "Press Y to continue or ENTER to exit"
    # Ends the program if the user does not press Y
    Until ($Output -ne "Y")
    HossFly, Exchange Administrator

  • Powershell script to add multiple domains to a transport rule

    I have a transport rule in Exchange 2013 that I created in the EAC (mail flow>rules).  it is set so *Apply this rule if.. the sender's domain is..  and then I entered a few domains.
    I want to use a powershell script to enter multiple domains into the senderdomainis parameter using the set-transportrule.  I would like to do this from a csv input file.  The file has  header row of domains and then the domains are listed
    under it.  This is also used successfully in a script that does content and sender id filter additions.
    I tried the following:
    $allowed = import-csv c:\temp\allowed.csv
    $Rule=get-transportrule "safe domain List"
    $Senderdomains =$rule.senderdomainis
    foreach($row in $allowed)
    $Senderdomains +=$row.domain
    #Set-Transportrule "Safe Domain List" -senderdomainis $Senderdomains
    It just adds a long line of all the domains mashed together without separation.
    Any ideas would be helpful.
    Thanks.

    This isn't the most elegant solution, but I was able to accomplish it with this script:
    $allowed = import-csv c:\temp\allowed.csv
    $domains=Get-TransportRule "Safe Domain List" | select -ExpandProperty senderdomainis
    foreach ($a in $allowed)
    $domains += $a.domain
    $domainstoadd = $domains | select -Unique
    Set-TransportRule "Safe Domain List" -SenderDomainIs $domainstoadd
    It's key to note that the column in the CSV file has a heading of "Domain". Basically the script pulls the existing array into a variable so you can add values from the CSV to the array. This creates duplicates,
    so the "Select -Unique" is a quick and easy way to eliminate the duplicates.

  • Creating multiple mailboxes using Powershell for users who already exist in AD

    Hi there,
    Wondering if anyone can help, I am wanting to use Powershell to run a command which references a CSV file to create a mailbox for a user who already exists in AD.
    It needs to reference the username, to ensure the correct user has a mailbox created (as mentioned they exist already in the domain), place them on a specific database (e.g DB1) and assign them an email address as well as possibly an alias email address
    too.
    Can anyone provide me the headings of the CSV file which would be needed as well as the powershell command to run. It would be great too if I could also set the quota sizes for the user at the same time of creating the mailbox, but if not possible or complicated
    I can run a script afterwards to do this. I would only want to warn them when their mailbox is 1.5GB in size and stop them sending when it reaches 2GB. 
    Thanks

    So create a csv file with the following headers and data
    UserID, Alias
    UserID should be the user SamAccountName, and the Alias is the Mailbox Alias that you want to set. Supposing that the csv file is named users.csv and located under C:\ , open the Exchange Management Console and run:
    $users = Import-Csv c:\users.csv
    Foreach ($user in $users) {
    Enable-Mailbox -Identity $user.UserID -alias $user.alias -database 'DB1'
    Set-Mailbox -Identity $user.UserID -IssueWarningQuota 1.5gb -ProhibitSendQuota 2gb 
    Please Mark As Answer if this helps
    ammarhasayen

  • How do you stop multiple users executing the same calc script at the same time?

    We have an issue when  users uplaod a spreadsheet and then run a calc script. at one time we have multiple exectuions of the script running.
    This slows up the system and we have to go cancel all the executions and run it again.
    Can we stop this and put them on a queue, so only one execution of the calc happens at one time. Or stop multiple executions getting submitted at all.

    You could use EXCLUSIVECALC to stop more than one calc running at the same time, although this will apply to all applications on your server.  And it doesn't just stop the same calc being launched twice.  Easier than the alternatives I can think of though, if it works for you.

  • Importing Photos and Music from Multiple users on the same Mac

    I am the same person with multiple users on one iMac. I need to have the same pics and music files on all of the user names on the one computer.
    I have the family pack MobileMe plan.
    Where are the files located for the photos and music in iTunes?
    I would like to import them from one user to another user on the same computer.
    Thank you

    Welcome to the Apple Discussions.
    If you Import the files from one User to another then you will use double the disk space on your HD as you will have multiple copies of everything. Why not simply share the files between accounts?
    For iPhoto 09 (version 8.0.2) and later:
    What you mean by 'share'.
    If you want the other user to be able to see the pics, but not add to, change or alter your library, then enable Sharing in your iPhoto (Preferences -> Sharing), leave iPhoto running and use Fast User Switching to open the other account. In that account, enable 'Look For Shared Libraries'. Your Library will appear in the other source pane.
    Any user can drag a pic from the Shared Library to their own in the iPhoto Window.
    Remember iPhoto must be running in both accounts for this to work.
    If you want the other user to have the same access to the library as you: to be able to add, edit, organise, keyword etc.
    Quit iPhoto in both accounts. Move the Library to the Users / Shared Folder
    (You can also use an external HD set to ignore permissions, a Disk Image or even partition your Hard Disk.)
    In each account in turn: Double click on the Library to open it. (You may be asked to repair the Library Permissions.) From that point on, this will be the default library location. Both accounts will have full access to the library, in fact, both accounts will 'own' it.
    However, there is a catch with this system and it is a significant one. iPhoto is not a multi-user app., it does not have the code to negotiate two users simultaneously writing to the database, and trying will cause db corruption. So only one user at a time, and back up, back up back up.
    Regards
    TD

  • Import PST files for multiple users at the same time?

    While importing PST files into archive mailboxes, the Exchange 2010 mailbox server went to 100% CPU and memory usage and I could not stop the imports because the EMS stopped responding.  We had to restart the whole server to get back to normal.
    Not sure if importing PSTs was the cause of it it was a coincidence.  We have done imports the same way before without this issue.
    How many PST imports can be done at the same time and how do we queue up multiple users and have the mailbox imports have unique names for each user?  I noticed they are always called MailboxImport and MailboxImport1 and then it starts over as MailboxImport
    again for additional users. So, if more than one user's PSTs are being imported at the same time, we will have multiple identically named imports running.
    We would like multiple users' PST imports to queue up and start automatically when the previous users' imports complete.

    Please try like this. Rename folder name same as alias.  i.e. \\server\share\<alias>. below are examples.
    "\\server\share\jsmith"
    "\\server\share\tjones"
    "\\server\share\rsmith"
    "\\server\share\bspears"
    "\\server\share\mmouse"
    And run below command to take PST from the corresponding
    foreach ($i in (Get-Mailbox)) { New-MailboxImportRequest -Mailbox $i -FilePath "\\Server\share\$($i.Alias)\$($i.Alias).pst" -baditemlimit 50 -acceptlargedataloss ;while ((Get-MailboxImportRequest -mailbox $i | ? {$_.Status -eq "Queued" -or $_.Status -eq "InProgress"})) { sleep 180 } }
    If a folder missing with the alias you will see an error similar to this.I think this will work for you. You just keep only the required PST folders to import in the "\\Server\share" folder. 
    "Unable to open PST file '\\server\share\mmouse\mmouse.pst'.
    Error details: Could
     not find a part of the path '\\server\share\mmouse\mmouse.pst'.
        + CategoryInfo          : NotSpecified: (0:Int32) [New-MailboxImportRequest], RemotePermanentException
        + FullyQualifiedErrorId : 27802833,Microsoft.Exchange.Management.RecipientTasks.NewMailboxImportRequest"
    Thanks, MAS
    Please mark as helpful if you find my comment helpful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you.

  • After creating a Powershell script monitor - how to import in Operation Manager 2012 ?

    Hello!
    I just completed all the steps in this article:
    http://social.technet.microsoft.com/wiki/contents/articles/16752.management-pack-composition-exercise-2-creating-a-monitor-based-on-a-windows-powershell-script.aspx?CommentPosted=true#commentmessage 
    So now I guess that the just created Management Pack should be imported in Operation Manager 2012, and then also folders and views should be created in order to have it showing green/red based on the values returned by the script.
    In the article there's no pointer to that procedure, so can you please provide a good link where the steps are explained?
    thanks!

    Have a look at the following video, it steps through how to create rules and monitors using PowerShell scripts
    https://technet.microsoft.com/en-us/video/how-do-i-create-a-rule-and-monitor-using-a-windows-powershell-script-in-a-system-center-operations-manager-management-pack.aspx
    Cheers,
    Martin
    Blog:
    http://sustaslog.wordpress.com 
    LinkedIn:
    Note: Posts are provided “AS IS” without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

  • How do I remove an imported iPhoto library at multiple users

    There seem to be different ways of sharing an iPhoto library among multiple users on a single Mac and I guess I didn't select the best one ...
    My wife and I both have an account on our Mac (I am administrator).
    Originally, only on my account we viewed our photos, but my wife wanted to have the same iPhoto access via her account.Makes sense!
    Via 'system preferences > share'  I marked the picture folder in which the iPhoto library is stored as a 'shared folder'.
    Then in my wifes account, I started iPhoto and I imported the iPhoto library file in this shared folder (and 'yes', I unchecked the option in the preferences menu to avoid copying photos on import ;-)
    Well, for the next hours or so, the system started to import the photos ... although my photo library contains more then 10.000 pictures (!!) the status bar during import indicated a shear amount of ±260.000 pictures to be imported (as it turns out it includes the 'faces' as pictures).
    To make a long story short - how do I restore iPhoto on my wifes account by e.g. removing/undoing the imported library. I am a bit hesitant in removing the library since it is the library stored in our shared folder and I don't want to delete that library file. I 'just' want it to turn back to the original 'empty' iPhoto on my Wife's account and share our library in a different way.
    By the way, although the iPhoto library/events are a mess on my wifes account, it still looks good on my account.
    Thanks.
    D.

    Trash the Library in your wife's account.
    Never import one Library to another. Every version and thumbnail is imported like a distinct photo, you lose all your Albums, Keywords etc., the link between Original and Previews is destroyed, the non-destructive editing feature is ruined and so on. In summary: it's mess.
    For iPhoto 09 (version 8.0.2) and later:
    What you mean by 'share'.
    If you want the other user to be able to see the pics, but not add to, change or alter your library, then enable Sharing in your iPhoto (Preferences -> Sharing), leave iPhoto running and use Fast User Switching to open the other account. In that account, enable 'Look For Shared Libraries'. Your Library will appear in the other source pane.
    Any user can drag a pic from the Shared Library to their own in the iPhoto Window.
    Remember iPhoto must be running in both accounts for this to work.
    If you want the other user to have the same access to the library as you: to be able to add, edit, organise, keyword etc.
    Quit iPhoto in both accounts. Move the Library to the Users / Shared Folder
    (You can also use an external HD set to ignore permissions, a Disk Image or even partition your Hard Disk.)
    In each account in turn: Double click on the Library to open it. (You may be asked to repair the Library Permissions.) From that point on, this will be the default library location. Both accounts will have full access to the library, in fact, both accounts will 'own' it.
    However, there is a catch with this system and it is a significant one. iPhoto is not a multi-user app., it does not have the code to negotiate two users simultaneously writing to the database, and trying will cause db corruption. So only one user at a time, and back up, back up back up.

  • How to create multiple users in solaris using script

    hi
    how i can create multiple users (2000 users) using shell script with a common password .
    useradd is creating one user at a time.
    thanks

    I m new to solaris and scripting also.
    how i can write a script for this .

  • How to give readonly Permission rights to 1000 users with button using powershell script?

    $site = Get-SPSite
    -Identity "http://mysite/"
    $user = Get-SPUser
    -Identity "mydomain\myuser"
    -Web $site.RootWeb
    $assignment = New-Object
    Microsoft.SharePoint.SPRoleAssignment($user)
    $role = $site.RootWeb.RoleDefinitions[[Microsoft.SharePoint.SPRoleType]::Reader]
    $assignment.RoleDefinitionBindings.Add($role);
    foreach ($web in $site.AllWebs)
        if ($web.HasUniquePerm)
            $web.RoleAssignments.Add($assignment)
    With above script I can give Readonly permission to the users...but at a time I can give permission to only one user...Actually 1000 users requires these permissionMy requirement is I will have a textbox and a button.I will enter username in textbox
    and when i clicked button the required permission should be assigned to the user given in the textbox...can you please tell how can i achieve this........how make to run powershell script when button is clicked.

    Hello,
    Instead of applying security to user level, it'll be better to create a SharePoint group where you will add the users. and use the outof the box interface to give permissions.
    and for your button, just add the direct link to add user
    http://serverurl/_layouts/15/aclinv.aspx?GroupId=7&IsDlg=1 
    replacing the group ID by the id of your new group (you can see it in the url when your are in the group)
    Best regards, Christopher.
    Blog |
    Mail
    Please remember to click "Mark As Answer" if a post solves your problem or
    "Vote As Helpful" if it was useful.
    Why mark as answer?

Maybe you are looking for

  • Ever since I got the new 6.1 update my wifi has turned off and greyed itself off. How do i fix this?

    Can someone please help me? I was told the only thing i can do is to go to the apple store and hope they'll do something for me. This is for my iphone 4s it only happened after the update but it worked fine at first but now is off and greyed out.

  • Instanceof Syntax Question:

    What is the proper way to find out if an Object is NOT an instance of a Class? What is the inverse of this: if (anObject instanceof Frame) {      // do something. }This works, but does not seem elegant: if (!(anObject instanceof Frame)) {      // do

  • My mac won't let me open mainstage

    i installed logic x onto my mac through the app store and it came with mainstage. i installed an update that my mac was bugging me for. now it won't let me open mainstage as it seems to think it was installed off a cd and i need the CD key which i do

  • Touch screen not working- another way to shut off phone?

    I don't know what happened- but all of a sudden my iPhone is frozen. I can get to the screen to shut the power off- but since I can't "slide" to shut it down, it's just stuck. I'm hoping a reboot will solve the problem... Is there any other way to sh

  • Java deployment woes

    Guys, I am banging my head with Java today.  I pushed it out silently but it broke a bunch of things. Is there a simple way (rule set seems complicated)  to set : set a website in the exception list lower the security to medium reset all security pro