Powershell - Bulk Set-ADUser attributes via a CSV file

I am attempting to do a Bulk replace of AD User account attributes via a CSV file.  Each line in this script works except the part of Set-ADUser where I enter -Replace $attribs. I'm not sure how to code this
part.
<#
The .csv file should have the following headers (first line)
GroupName,Status,Approver1,Approver2,Owner
#>
#Import CSV
$csv = @()
$csv = Import-Csv -Path "C:\TempAdd_Grp_Attrib.csv"
#Loop through all items in the CSV
ForEach ($item In $csv)
$gname = $item.GroupName
$attribs = @{'extensionAttribute2'=$item.Status; 'extensionAttribute3'=$item.Approver1; 'extensionAttribute4'=$item.Approver2; 'managedBy'=$item.Owner}
Set-ADGroup -Identity $gname #-Replace $attribs
mamadukes

Yes. I am attempting to update the AD Group extension attributes.
The code below works, but I know I can streamline this if I use the INSTANCE, which I am having an issue with (Set-ADGroup -Instance $Update)
Import-Module ActiveDirectory
<#
The .csv file should have the following headers (first line)
GroupName,Status,Approver1,Approver2,Owner
#>
#Import CSV
$date = get-date -Format "MMddyyyymm"
$csv = @()
$csv = Import-Csv -Path "C:\Temp\Add_Grp_Attrib2.csv"
#Loop through all items in the CSV
ForEach ($item In $csv)
$Update=(Get-ADGroup $item.GroupName -Properties extensionAttribute2,extensionAttribute3,extensionAttribute4,ManagedBy);
$Update."extensionAttribute2"=$item.Status
$Update."extensionAttribute3"=$item.Approver1
$Update."extensionAttribute4"=$item.Approver2
# Set-ADGroup -instance $Update
Set-ADGroup -Identity $item.groupName -ManagedBy $item.Owner
Get-ADGroup $item.GroupName -Properties extensionAttribute2,extensionAttribute3,extensionAttribute4,ManagedBy | select name,extensionAttribute2,extensionAttribute3,extensionAttribute4,ManagedBy | Export-Csv "C:\temp\Add_Grp_Attrib_Updates_$date.csv" -NoTypeInformation
mamadukes

Similar Messages

  • PowerShell - Bulk-New-ADUser Creation via a csv file

    This script creates bulk AD users via a csv file. The script creates & configures the user accounts correctly even though the following error message appears. How can I correct this?
    Set-Locaiton : Cannot find path 'AD:Mydomain,OU=MyDomain,DC=My,DC=Domain,DC=org' because it does not exist.
    Import-Module ActiveDirectory
    $csv = Import-CSV -Path "C:\Temp\CreateUsers.csv"
    cd AD:
    set-location -path "OU=MyDomain,DC=My,DC=Domain,DC=org" -PassThru
    foreach($Item in $csv){
    $newUserID=@{
    Name=$item.userID
    Description=$item.description
    GivenName=$item.UserID
    surName=$item.UserID
    DisplayName=$item.UserID
    UserPrincipalName=$item.UserID + "@MyDomain.org"
    EmployeeID=$item.Owner
    ScriptPath="login.cmd"
    Try{
    New-ADUser @newUserID -ErrorAction Stop -AccountPassword (ConvertTo-SecureString $Item.Password -AsPlainText -Force) -PassThru
    Enable-ADAccount -Identity $item.userID
    Set-ADUser -Identity $item.userID -ChangePasswordAtLogon $true
    Write-Host "UserID $($item.UserID) created!" -ForegroundColor green
    Catch{
    Write-Host "There was a problem creating UserID $($item.UserID). The account was not created!" -ForegroundColor Red
    set-location -path "c:\temp"
    mamadukes

    Slight variation, populated from the AdventureWorks SQL database rather than a CSV
    Import-Module "SQLPS" -DisableNameChecking
    New-PSDrive -Name AWDB -PSProvider SQLServer -ROOT SQLSERVER:\sql\localhost\default\databases\adventureworks2012
    Set-Location AWDB:\Tables
    $SQLText = "SELECT e.BusinessEntityID, p.Title, p.FirstName, p.MiddleName, p.LastName, p.Suffix, "+
    "e.JobTitle, d.Name AS Department, d.GroupName, edh.StartDate, e.LoginID"+
    " FROM HumanResources.Employee AS e"+
    " INNER JOIN Person.Person AS p ON p.BusinessEntityID = e.BusinessEntityID"+
    " INNER JOIN HumanResources.EmployeeDepartmentHistory AS edh ON e.BusinessEntityID = edh.BusinessEntityID"+
    " INNER JOIN HumanResources.Department AS d ON edh.DepartmentID = d.DepartmentID"+
    " WHERE (edh.EndDate IS NULL)"+
    " AND (p.FirstName ='Brian')"
    $Query = Invoke-SQLCmd -Query $SQLText
    $Password = "P@assword1"
    foreach($Item in $Query)
    $LoginID=$Item.LoginID
    $LoginID="CORP\"+($LoginID).Substring(16)
    $newUserID=@{
    Name=$item.FirstName+$Item.LastName
    Description="This is a test of a bulk user add"
    GivenName=$item.FirstName
    Surname=$item.LastName
    DisplayName=$item.FirstName+" "+$Item.LastName
    UserPrincipalName="$($item.FirstName+"."+$Item.LastName)@corp.contoso.com"
    EmployeeID=$item.BusinessEntityID
    ScriptPath='login.cmd'
    Company="Contoso"
    Department=$Item.Department
    EmailAddress="$($item.FirstName+"."+$Item.LastName)@corp.contoso.com"
    Title=$Item.JobTitle
    $TargetOU="OU="+$item.Department+",DC=corp,DC=contoso,DC=com"
    Try{
    $newUserID
    New-ADUser @newUserID -Path $TargetOU -ErrorAction Stop -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Passthru
    Enable-ADAccount -Identity $newUserID.Name
    Set-ADUser -Identity $newUserID.Name -ChangePasswordAtLogon $true
    Write-Host "UserID $($newUserID.Name) created!" -ForegroundColor green
    Catch{
    Write-Host "There was a problem creating UserID $($item.UserID). The account was not created!" -ForegroundColor Red
    No need to be on the PSDrive AD:, the OU can be specified in the Path parameter in the New-ADUser.
    This was done on a member server with SQL Server (not a domain controller).
    Thanks for your help

  • Time machine Bulk setting Spotlight attributes failed

    Hi,
    I'm having big, ongoing problems with a customers iMac, 10.6.7, when trying to use Time Machine.
    All i want to do now is start afresh.  And want to make sure i clear out everything.  It's no longer the priority to find out what is the cause.
    Here's the setup, and what i plan to do.  If i miss anything, please point out.
    the setup:
    iMac, connected via ethernet, to a Ethernet over Power plug (Airport switched off on iMac)
    EoP plug then connected to Time Capsule, which is in turn connected to the modem
    Internet connection is fine / other mac connected direct to TC backs up fine.
    Mac with the problem (unfortunately i only get the info second hand, after i've visited):
    TM Sys Pref Pane reports No errors, just that the last completed back up was 7th June
    When TM goes through process, it reports 'Preparing xxxxxxxxx items'
    Then takes forever to back up a reported 40GBs, reports something like '4KB completed', then '225MB completed, then back to 10KB completed...', then 'Calculating Changes...'
    There's never any error message, still reports last back up to be 7th of June.  Finally installed backup buddy widget and got the 'bulk setting Spotlight attributes failed' and "Stopping back up to allow ejection of back up destination disk".
    Things tried:
    repairing sparceimage of back in disk utility
    deleting prefs for TM in /Library/prefs
    Tried forcing new back up (without deleting the old one) by renaming the sparcebundle to '...old.sparcebundle' - it carried on trying to back up to the old one, as indicated by the Date Modified in the Get Info window, and lack of new .sparcebundle on TC.
    What i plan to do, to thoroughly reset Time Machine, when i visit (I won't have time /opportunity to hang around, wait for anything.  I just do this sequence of events, then i have to leave, not by choice.  So it's important i get it right, do a thorough reset.):
    Switch off TM on problematic iMac
    Delete the .sparcebundle for the problematic iMac from the TC
    Delete /Library/Prefs/com.apple.TimeMachine.plist on problematic iMac
    Rebuild spotlight index cache: sudo mdutil -E
    Shutdown
    Unplug EoP plugs for 30 seconds / replace ethernet cables
    Restart iMac
    Turn on TM, set up to backup to TC
    Now, surely, this is starting totally afresh.  It is assumed the TC is ok, because another iMac directly connected backs up, no problem, and the SMART status of the TC drive is not reporting problems.
    If i'm missing anything, any comments, or just reassurance, would love to hear comments.  This has been quite traumatic!  And is dragging on way too long, and made more difficult by the fact i can only visit in short time frames, and the results take so long to come through.
    Many thanks,
    C

    Col Kav wrote:
    Ah, ok,  this would be system.log, and then filter 'backupd' ?
    Yup.  And when you find a problem, it might be worth noting the time, removing the filter, and see if there are other messages at about the same time that might be contributing to the problem.
    But as it's going via Ethernet-over-Power plugs, which are 200mbps, excuse my patchy knowledge, but would this account for slowness?  Speed isn't a priority, i mean, just as long as everything got backed up.
    Of course -- they're getting 10% of the speed.  Earlier you posted "I know Time Machine generally takes ages to do the first backup, but is there any reason why it should take 20 minuites+ to make the backup disk available?"  20 minutes is certainly a long time, but if they're only getting 10% of the speed they should, that's gotta be a big part of it.
    The thing is, the internet access is fine, and this customer has offline backups with carbonite.
    If they're trying to do backups and any serious internet access over the same "pipe," it's gonna be very slow. Depending on what they're doing, they may not notice how slow response time is.
    The external disk isn't an option.  i mean, he has the TC, he wants that to work.  Which is fair enough.
    Even if it's like molasses? 
    Can you even temporarily connect the iMac directly to the TC via Ethernet?  If so, see how much faster it is.
    I don't see the point of the TC.  Is it being used wirelessly for anything at all? 
    Since everything's connected by cable anyway, why not plug an external HD into the iMac? 
    From your first post:
    When TM goes through process, it reports 'Preparing xxxxxxxxx items'
    Then takes forever to back up a reported 40GBs, reports something like '4KB completed', then '225MB completed, then back to 10KB completed...', then 'Calculating Changes...'
    That sounds like TM is simply making two "passes," which is common.  If additional changes are made while it's doing the first one, it will make a second pass to catch up what's ordinarily small and quickly backed-up.  You'll see that in the logs.
    But the network or whatever problem is preventing a completed backup; so on each backup, TM isn't sure it got everything the last time (you'll see a UUID message).  Because of that, it will do a "deep traversal," with a message, comparing everything on the Mac to the most recent completed backup, to figure out what's changed and needs to be backed-up.  With an excruciatingly slow connection, that's going to take forever.  And that will be repeated on each backup attempt until one completes normally.

  • Backup failed - Bulk setting Spotlight attribute failed - Ideas?

    I just upgraded from 10.4.? to 10.5.4 primarily to use TM. This has been a disaster. I have never had this much trouble with an upgrade since the Mac Plus.
    Before the backup fails I get 200+ console messages like:
    /System/Library/CoreServices/backupd[294] Bulk setting Spotlight attributes failed.
    What does this mean and how can I fix the problem?
    From other posts, it seems that Spotlight and TM have some type of incompatibility, particularly on the first full backup. Spotlight indexing seems to create a problem for TM. I have yet to perform a successful backup.
    How do I temporarily turn Off Spotlight other than editing the hostconfig file? Should I include both my Backup Drive and my Boot drive in the Spotlight exclusion list, until I can get a successful backup?

    Yes,
    Before the backup I placed the TM Backup drive in the "Privacy" section of the Spotlight preferences. That did not seem to have an effect.
    The bad news is that at least for now, I am using the backup drive to hold data as well. By placing the drive in the Privacy section, I no longer can easily search the contents.
    -reed

  • Issue Setting Resource Attributes via Workflow Process

    I'm currently trying to set resource attributes via a workflow process, but for whatever reason the attribute is not detected as "changed" and the update object has nothing about the attribute. I'm wondering if I'm just doing something wrong with the way I'm setting it, or if I'm missing a piece to apply the upate.
    What I'm doing is...
    1. Checking out the user view
    2. updating the attribute via code something like this...
    <set name='user.accounts[ldap].attributeIWantToChange'>
    Logic in here
    </set>
    3. then I'm checking the view back in.
    Anyone know why this isn't working(I can set other attributes like waveset.roles fine this way)?
    Edited by: UNO-AD-HM on Jul 6, 2009 12:54 PM

    Figured it out, have to load a different form in when I check the view out, the tabbed user's form will not update resource attributes.

  • A 30GB incremental backup ("Bulk setting Spotlight attributes failed")

    Greetings all
    I have TM set only to back up my home account which lives on a separate hard drive. This is the only drive backed up by TM (the system drive is cloned using SuperDuper instead). The total size of the home account drive is 190GB.
    All day today, I have been working with images, creating roughly 1.5GB of new data. And TM has dutifully backed up this new data in a few incremental backups.
    This evening TM suddenly backed up 30GB of data, 9722 files, from the home account drive. I haven't touched anything on this drive, except my image folders.
    Is there any way to find out more precisely what was backed up so I can remove the duplicates from within TM?
    I've scoured Console and the TM Buddy widget for info on what was copied but can't find anything.
    I have looked in the backups.backupdb folder. The relevant folder with the time stamp of the big backup is listed in the Get info window as 4.5GB. Some other backup folders are listed as 180-190GB.
    One thing to note:
    The culprit incremental backup left 8 *"Bulk setting Spotlight attributes failed"* messages in the log. I have never seen these before. Of course, TM is excluded from Spotlight and has been so for a long time.
    I'm not running any virtualisation, Entourage or such. I haven't made any hardware changes recently.
    Thanks for any insight.
    /p

    You might want to download the TimeTracker app, from www.charlessoft.com.
    It shows most of the files saved by TM for each backup (excluding some hidden/system files, etc.).
    Thanks Pondini. TimeTracker is very helpful. It shows that what was backed up was just under half of my iTunes library. There's no rhyme or reason as to why the music of certain artists was backed up.
    I can only think this has to do with is the installation of iTunes update 8.1 which happened a few days prior to the big backup. I can't remember if I've used iTunes since. Maybe that made some change to the iTunes library so TM thinks certain music is new?
    That appears to be Spotlight and TM falling over each other. Try excluding your TM disk from Spotlight (System Preferences > Spotlight > Privacy).
    Actually TM is always excluded from Spotlight. In fact, I remember verifying this before I cloned my system onto an external drive prior to installing the iTunes and Frontrow updates.
    I might simply start all over with TM.
    This reminds me of some thoughts on backup strategy I've had recently. Basically, I've been toying with the idea of using only one folder, for instance the Desktop, as the "active" folder into which I would put stuff I'm working on, which is mainly images and documents. TM could be set only to back up this folder in order to protect against accidental deletions.
    Once I'm done with a file, I would move it to the final archive area. Rather than using TM for that archive, I would be using SuperDuper's schedule function.
    /p

  • Set OU Attribute via Script

    Is it possible to set the "ou" attribute of a computer object in AD via script?  That attribute is not listed as an option in Set-ADComputer and it doesn't auto-populate based on the OU the object is in.  How can I programatically set
    the attribute rather than modifying each individual object manually?

    You can populate it with Set-ADComputer.
    Set-ADcomputer -Identity xxx -add @{ou="yyy"}
    This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.
    Get Active Directory User Last Logon
    Create an Active Directory test domain similar to the production one
    Management of test accounts in an Active Directory production domain - Part I
    Management of test accounts in an Active Directory production domain - Part II
    Management of test accounts in an Active Directory production domain - Part III
    Reset Active Directory user password

  • Need to create new users in Office 365 with custom attributes from a csv file

    I am exporting users from an active directory environment and then deleting them from AD. They are Alumni and will no longer be in AD.
    I have a csv file with the following fields that I need to use to create new Alumni email boxes in Office 365 for. I need the CustomAttributes because my Dynamic Distribution Groups use them. I am fairly new to PowerShell and have been unable to get this
    to work. I suspect I may have to split it into two parts, but am not sure how to proceed. Any assistance would be appreciated. I was directed here from the Office 365 community.
    Import-Csv -Path c:\CSVfiles\CreateAlumni.csv | ForEach-Object {
       New-MsolUser -FirstName $_.FirstName -LastName $_.LastName
       -UserPrincipalName $_.UserPrincipalName
       -DisplayName "$($_.FirstName) $($_.LastName)"
       -Password $_.Password
       -CustomAttribute1 $_.CustomAttribute1
       -CustomAttribute3 $_.CustomAttribute3
       -CustomAttribute10 $_.CustomAttribute10
       -CustomAttribute11 $_.CustomAttribute11
       -CustomAttribute12 $_.CustomAttribute12
       -LicenseAssignment 'domaincom:EXCHANGESTANDARD_ALUMNI'
       -UsageLocation US

    Ok, it wasn't stopping after 2 iterations. What I was seeing was 2 failures. The first was the Get-Mailbox command and the second was when it tried to assign attributes. For some reason it is not looping when it fails. It just goes on and tries to assign
    the Custom Attributes. I added writes in to tell me what was happening.
    ### Check if mailbox is provisioned yet
    Write-Host "Checking if mailbox is provisioned yet..." -foregroundcolor yellow
    $found = $false
    $count = 0
    Do {
    try {
    Get-Mailbox -Identity $_.UserName -ErrorAction Stop
    $found = $true
    Write-Output 'Mailbox found. Details:'
    Get-Mailbox -Identity $_.UserName
    } catch {
    Write-Output 'Sleeping'
    $count++
    Start-Sleep -Seconds 5
    If ($count -ge 12) {
    Write-Output 'Mailbox not found. Quitting.'
    $found = $true
    } Until ($found)
    Write-Host "Adding Custom Attributes to User" -foregroundcolor yellow
    Set-Mailbox -Identity $_.UserName -CustomAttribute1 $_.CustomAttribute1 -CustomAttribute3 $_.CustomAttribute3 -CustomAttribute10 $_.CustomAttribute10 -CustomAttribute11 $_.CustomAttribute11 -CustomAttribute12 $_.CustomAttribute12
    Write-Output "User has been Provisioned in Office 365!" -foregroundcolor yellow
    Checking if mailbox is provisioned yet...
    The operation couldn't be performed because object 'Joe.Cool2003' couldn't be found on 'CO1PR07A002DC01.NAMPR07A002.prod.outlook.com'.
        + CategoryInfo         
    : NotSpecified: (:) [Get-Mailbox], ManagementObjectNotFoundException
        + FullyQualifiedErrorId : [Server=CO1PR07MB125,RequestId=e1aabda1-01e4-4f68-984e-e20be0975242,TimeStamp=5/22/2014 4:23:59 AM] [FailureCategory=Cmdlet-ManagementObj
       ectNotFoundException] 2788FB48,Microsoft.Exchange.Management.RecipientTasks.GetMailbox
        + PSComputerName        : pod51038psh.outlook.com
    Mailbox found. Details:
    The operation couldn't be performed because object 'Joe.Cool2003' couldn't be found on 'CO1PR07A002DC01.NAMPR07A002.prod.outlook.com'.
        + CategoryInfo         
    : NotSpecified: (:) [Get-Mailbox], ManagementObjectNotFoundException
        + FullyQualifiedErrorId : [Server=CO1PR07MB125,RequestId=16a8a2bc-333a-455c-8504-e0b99c44c334,TimeStamp=5/22/2014 4:24:00 AM] [FailureCategory=Cmdlet-ManagementObj
       ectNotFoundException] 2788FB48,Microsoft.Exchange.Management.RecipientTasks.GetMailbox
        + PSComputerName       
    : pod51038psh.outlook.com
    Adding Custom Attributes to User
    The operation couldn't be performed because object 'Joe.Cool2003' couldn't be found on 'CO1PR07A002DC01.NAMPR07A002.prod.outlook.com'.
        + CategoryInfo         
    : NotSpecified: (:) [Set-Mailbox], ManagementObjectNotFoundException
        + FullyQualifiedErrorId : [Server=CO1PR07MB125,RequestId=8319d220-b9dd-492f-8182-5083cf56e58b,TimeStamp=5/22/2014 4:24:00 AM] [FailureCategory=Cmdlet-ManagementObj
       ectNotFoundException] C7844A24,Microsoft.Exchange.Management.RecipientTasks.SetMailbox
        + PSComputerName       
    : pod51038psh.outlook.com
    User has been Provisioned in Office 365!
    Of course the user has been provisioned, but the CustomAttributes have not been assigned. :(

  • Bulk Insert into a Table from CSV file

    I have a CSV file with 1000 records and i have to insert those records into a table.
    I tried for Bulk Insert command and Load data infile command but it throws error.
    Am using Oracle 10g Express Edition.
    I want to achieve it thru query command and not by plsql procedures
    Please send me query syntax for this problem. . . .
    Thanks in Advance,
    Hariharan ST.

    Hi
    If you create an external table that points to your csv file you will then be able populate your table from a query.
    See: http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11210
    Hope this helps

  • Import Export of contacts via ASCII CSV file

    Hi all. I have a 9300 Curve. This is my phone. I had a workphone which was a 9900 Bold. I backed up the Bold when i left the job. I want to import the contacts from the Bold back up into the Curve. If i export the Curve contacts to a csv file. Then import the bold contacts from restoring just the contacts list.... so far ok, bold contacts in, curve contacts overwritten but they are in a file as csv. I then try to one way sync the curve contacts back in.....the csv file has removed all the zeros from the start of every number. If you "edit" the csv in notepad they are there but when you look via excel...they are not. If i sync back in....the zero's are gone. I do not want to sync with windows live or anything like that as it will import a whole heap of **bleep** i dont want as well.
    Any clues?
    Thanks

    *Feedback*
    "Use the form below to send us your comments. We read all feedback carefully, but please note that we cannot respond to the comments you submit."
    http://www.apple.com/feedback/ipad.html
    Airstash
                                            Compatibility                               
                                            Wireless operation:                               
                                                    Web browser WiFi b/g capable device                                       
                                                    Optimized experience for iPhone, iPod touch, and iPad via HTML5                                       
                                                    No internet connection required                                       
                                            USB operation:                               
                                                    Compatible with most operating systems that support USB Mass Storage Class (thumb drives)                                       
                                                    Firmware update via file drag and drop                                       
    http://www.airstash.com/

  • Problem in bulk creation of Virtual machines using .csv file

    Hello Guys
    the problem is self-explanatory so i only put the screen shot here:
    import-csv D:\2.csv |
    ForEach-Object { new-vm -Name $_.VMname -MemoryStartupByte $_.memory -Path 'c:\testfolder' -NewVHDPath $_.myvhdpath -NewVHDSizeBytes $_.myvhdsize }
    the error message is :
    New-VM : Cannot bind parameter 'MemoryStartupBytes'. Cannot convert value "1024MB" to type "System.Int64". Error: "Input string was not in a correct format."
    At C:\Untitled2.ps1:2 char:82
    + ... oryStartupByte $_.memory -Generation 2 -Path 'c:\testfolder' -NewVHDPath $_.myvh ...
    +                    ~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-VM], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.HyperV.PowerShell.Commands.NewVMCommand
    New-VM : Missing an argument for parameter 'Name'. Specify a parameter of type 'System.String' and try again.
    At C:\Untitled2.ps1:5 char:8
    + new-vm -Name
    +        ~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-VM], ParameterBindingException
        + FullyQualifiedErrorId : MissingArgument,Microsoft.HyperV.PowerShell.Commands.NewVMCommand
    i usually search before asking problems but here i really don't know what to search about this certain situation.
    i guest there must be something related to variables in powershell !
    thanks in advanced

    That's all there is. The $x now contains the number you want.
    ¯\_(ツ)_/¯
    no, you didn't guide me.
    i asked you where is the location of your writings :
    $num='1732Mb' 
    [scriptblock]::Create($num).Invoke()[0]
    $x=[scriptblock]::Create($num).Invoke()[0]
    $x.GetType()
    in my code :
    import-csv D:\2.csv |
    ForEach-Object { new-vm -Name $_.VMname -MemoryStartupByte $_.memory -Path 'c:\testfolder' -NewVHDPath $_.myvhdpath -NewVHDSizeBytes $_.myvhdsize }
    how i must use these two codes along with eachother? i understand them separatly but how to use them together?
    if i was instead of you & i wanted to guide someone, i would help him in this way:
    1- first type this block:
    2- then write this
    3- then write this
    4- at the end your final script would be ......

  • Setting UIManager properties via swing.properties file

    Folks'es,
    I would like to change some default settings of existing Swing Applications, eg font size. The API doc for UIManager mentions the file swing.properties and three levels of defaults, that are being searched/used.
    How can I set up these 3 levels? Where are their settings defined?
    Can some kind soul pls enlighten me, as to how to setup swing.properties? The only thing I could get to work was setting the L&F (I got an error message when setting the Windows L&F on Solaris :).
    here are some lines I tried, but they don't have any effect:label.font=javax.swing.plaf.FontUIResource[family\=Dialog,name\=Dialog,style\=plain,size\=40]
    table.font=javax.swing.plaf.FontUIResource[family\=Dialog,name\=Dialog,style\=plain,size\=20]
    table.color=javax.swing.plaf.ColorUIResource[r\=255,g\=0,b\=0]
    button.background=javax.swing.plaf.ColorUIResource[r\=255,g\=0,b\=0]they don't make a lot of sense, i know, i just want to get a handle on this.
    and yes, i tried upper/lower case, qutoes, etc etc
    stuck and desperate after hunting all morning through the forums...
    thomas
    Message was edited by:
    kloeber

    to me there is the main question: where does a
    Swing L&F gets its default properties from and From the L&F class. Take a look at the source for MetalLookAndFeel. Granted, this is not a very well developed L&F, from a code perspective. There are numerous inconsistencies in how things are used throughout the various UI delegates. (And don't get me started on the subclass-ability of Basic/Metal classes.)
    I've recently written my own L&F for a project that started by using Metal as a basis, and had to rip out or rewrite so much, it really shows why few people write L&F's for Swing.
    is there a way of overwriting them 'from the outside',
    ie can users change them to suit their individual taste.There is nothing that I can see that is any standard mechanism in Swing to support this. I think it comes down to you just have to implement it yourself.
    In my recent experiences with working on a L&F, the problems come down to this:
    a) The first time you look at the code for Metal/Basic, it's extremely intimidating how much.
    b) You think you can subclass a lot, but once you realize you can't without rewriting large chunks and start really looking at the code in detail, you really get intimidated, and a bit mad at Sun.
    c) Finally you either give up, or realize you have to pick your battles. For example, coping some classes outright to tweak a couple things.
    You really need to take time to understand how it all works (and there's no really good documentation). It's nearly a full time job to work thru a L&F.

  • Set-ADUser based on .csv file - empty attributes issue

    Hi, after a few months without working with PowerShell my knowledge is slowly fading away but fortunately every time this happened before, I was able to rebuild my knowledge again and now it is the same story. However I want to optimize my simple
    code which populates three AD user object attributes: manager, officephone and fax with values stored in .csv file. Everything works well, but my code looks not so good in my opinion. Is there any more elegant solution?
    $AddressBook = Import-CSV -Path D:\AddressBookFinal.csv
    foreach($Employee in $AddressBook)
         if([string]::IsNullOrEmpty($Employee.ManagerUserName)) {
                  Set-ADUser -Identity $Employee.EmployeeUserName -Manager $null
        } else {
                  Set-ADUser -Identity $Employee.EmployeeUserName -Manager $Employee.ManagerUserName
        <#similar code here for checking value of OfficePhone and Fax attributes and populating             AD attributes depending on if attribute value in .csv file is empty or not#> 

    Hi BoxiKG,
    If there is any other question regarding this issue, please feel free to reply this post directly so we will be notified to follow it up.
    If you have any feedback on our support, please click here.
    Best Regards,
    Anna Wang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • SQL bulk copy from csv file - Encoding

    Hi Experts
    This is the first time I am creating a PowerShell script and it is almost working. I just have some problems with the actual bulk import to SQL encoding from the text file since it replaces
    special characters with a question mark. I have set the encoding when creating the csv file but that does not seem to reflect on the actual bulk import. I have tried difference scenarios with the encoding part but I cannot find the proper solution for that.
    To shortly outline what the script does:
    Connect to Active Directory fetching all user - but excluding users in specific OU's
    Export all users to a csv in unicode encoding
    Strip double quote text identifiers (if there is another way of handling that it will be much appreciated)
    Clear all records temporary SQL table
    Import records from csv file to temporary SQL table (this is where the encoding is wrong)
    Update existing records in another table based on the records in the temporary table and insert new record if not found.
    The script looks as the following (any suggestions for optimizing the script are very welcome):
    # CSV file variables
    $path = Split-Path -parent "C:\Temp\ExportADUsers\*.*"
    $filename = "AD_Users.csv"
    $csvfile = $path + "\" + $filename
    $csvdelimiter = ";"
    $firstRowColumns = $true
    # Active Directory variables
    $searchbase = "OU=Users,DC=fabrikam,DC=com"
    $ADServer = 'DC01'
    # Database variables
    $sqlserver = "DB02"
    $database = "My Database"
    $table = "tblADimport"
    $tableEmployee = "tblEmployees"
    # Initialize
    Write-Host "Script started..."
    $elapsed = [System.Diagnostics.Stopwatch]::StartNew()
    # GET DATA FROM ACTIVE DIRECTORY
    # Import the ActiveDirectory Module
    Import-Module ActiveDirectory
    # Get all AD users not in specified OU's
    Write-Host "Retrieving users from Active Directory..."
    $AllADUsers = Get-ADUser -server $ADServer `
    -searchbase $searchbase -Filter * -Properties * |
    ?{$_.DistinguishedName -notmatch 'OU=MeetingRooms,OU=Users,DC=fabrikam,DC=com' `
    -and $_.DistinguishedName -notmatch 'OU=FunctionalMailbox,OU=Users,DC=fabrikam,DC=com'}
    Write-Host "Users retrieved in $($elapsed.Elapsed.ToString())."
    # Define labels and get specific user fields
    Write-Host "Generating CSV file..."
    $AllADUsers |
    Select-Object @{Label = "UNID";Expression = {$_.objectGuid}},
    @{Label = "FirstName";Expression = {$_.GivenName}},
    @{Label = "LastName";Expression = {$_.sn}},
    @{Label = "EmployeeNo";Expression = {$_.EmployeeID}} |
    # Export CSV file and remove text qualifiers
    Export-Csv -NoTypeInformation $csvfile -Encoding Unicode -Delimiter $csvdelimiter
    Write-Host "Removing text qualifiers..."
    (Get-Content $csvfile) | foreach {$_ -replace '"'} | Set-Content $csvfile
    Write-Host "CSV file created in $($elapsed.Elapsed.ToString())."
    # DATABASE IMPORT
    [void][Reflection.Assembly]::LoadWithPartialName("System.Data")
    [void][Reflection.Assembly]::LoadWithPartialName("System.Data.SqlClient")
    $batchsize = 50000
    # Delete all records in AD import table
    Write-Host "Clearing records in AD import table..."
    Invoke-Sqlcmd -Query "DELETE FROM $table" -Database $database -ServerInstance $sqlserver
    # Build the sqlbulkcopy connection, and set the timeout to infinite
    $connectionstring = "Data Source=$sqlserver;Integrated Security=true;Initial Catalog=$database;"
    $bulkcopy = New-Object Data.SqlClient.SqlBulkCopy($connectionstring, [System.Data.SqlClient.SqlBulkCopyOptions]::TableLock)
    $bulkcopy.DestinationTableName = $table
    $bulkcopy.bulkcopyTimeout = 0
    $bulkcopy.batchsize = $batchsize
    # Create the datatable and autogenerate the columns
    $datatable = New-Object System.Data.DataTable
    # Open the text file from disk
    $reader = New-Object System.IO.StreamReader($csvfile)
    $columns = (Get-Content $csvfile -First 1).Split($csvdelimiter)
    if ($firstRowColumns -eq $true) { $null = $reader.readLine()}
    Write-Host "Importing to database..."
    foreach ($column in $columns) {
    $null = $datatable.Columns.Add()
    # Read in the data, line by line
    while (($line = $reader.ReadLine()) -ne $null) {
    $null = $datatable.Rows.Add($line.Split($csvdelimiter))
    $i++; if (($i % $batchsize) -eq 0) {
    $bulkcopy.WriteToServer($datatable)
    Write-Host "$i rows have been inserted in $($elapsed.Elapsed.ToString())."
    $datatable.Clear()
    # Add in all the remaining rows since the last clear
    if($datatable.Rows.Count -gt 0) {
    $bulkcopy.WriteToServer($datatable)
    $datatable.Clear()
    # Clean Up
    Write-Host "CSV file imported in $($elapsed.Elapsed.ToString())."
    $reader.Close(); $reader.Dispose()
    $bulkcopy.Close(); $bulkcopy.Dispose()
    $datatable.Dispose()
    # Sometimes the Garbage Collector takes too long to clear the huge datatable.
    [System.GC]::Collect()
    # Update tblEmployee with imported data
    Write-Host "Updating employee data..."
    $queryUpdateUsers = "UPDATE $($tableEmployee)
    SET $($tableEmployee).EmployeeNumber = $($table).EmployeeNo,
    $($tableEmployee).FirstName = $($table).FirstName,
    $($tableEmployee).LastName = $($table).LastName,
    FROM $($tableEmployee) INNER JOIN $($table) ON $($tableEmployee).UniqueNumber = $($table).UNID
    IF @@ROWCOUNT=0
    INSERT INTO $($tableEmployee) (EmployeeNumber, FirstName, LastName, UniqueNumber)
    SELECT EmployeeNo, FirstName, LastName, UNID
    FROM $($table)"
    try
    Invoke-Sqlcmd -ServerInstance $sqlserver -Database $database -Query $queryUpdateUsers
    Write-Host "Table $($tableEmployee) updated in $($elapsed.Elapsed.ToString())."
    catch
    Write-Host "An error occured when updating $($tableEmployee) $($elapsed.Elapsed.ToString())."
    Write-Host "Script completed in $($elapsed.Elapsed.ToString())."

    I can see that the Export-CSV exports into ANSI though the encoding has been set to UNICODE. Thanks for leading me in the right direction.
    No - it exports as Unicode if set to.
    Your export was wrong and is exporting nothing. Look closely at your code:
    THis line exports nothing in Unicode"
    Export-Csv -NoTypeInformation $csvfile -Encoding Unicode -Delimiter $csvdelimiter
    There is no input object.
    This line converts any file to ansi
    (Get-Content $csvfile) | foreach {$_ -replace '"'} | Set-Content $csvfile
    Set-Content defaults to ANSI so the output file is converted.
    Since you are just dumping into a table by manually building a recorset why not just go direct.  You do not need a CSV.  Just dump theresults of the query to a datatable.
    https://gallery.technet.microsoft.com/scriptcenter/4208a159-a52e-4b99-83d4-8048468d29dd
    This script dumps to a datatable object which can now be used directly in a bulkcopy.
    Here is an example of how easy this is using your script:
    $AllADUsers = Get-ADUser -server $ADServer -searchbase $searchbase -Filter * -Properties GivenName,SN,EmployeeID,objectGUID |
    Where{
    $_.DistinguishedName -notmatch 'OU=MeetingRooms,OU=Users,DC=fabrikam,DC=com'
    -and $_.DistinguishedName -notmatch 'OU=FunctionalMailbox,OU=Users,DC=fabrikam,DC=com'
    } |
    Select-Object @{N='UNID';E={$_.objectGuid}},
    @{N='FirstName';Expression = {$_.GivenName}},
    @{N='LastName';Expression = {$_.sn}},
    @{N=/EmployeeNo;Expression = {$_.EmployeeID}} |
    Out-DataTable
    $AllDUsers is now a datatable.  You can just upload it.
    ¯\_(ツ)_/¯

  • How to create a csv file with NCS attributes?

    Hi
    i installed Cisco Prime NCS and trying to perform bulk update of device credentials with csv file.
    How to create a csv file with all required attributes?
    This is part of NCS online help talking about this topic:
    Bulk Update Devices—To update the device credentials in a bulk, select Bulk Update Devices from the Select a command drop-down list. The Bulk Update Devices page appears.You can choose a CSV file.
    Note        The CSV file contains a list of devices to be updated, one device per line. Each line is a comma separated list of device attributes. The first line describes the attributes included. The IP address attribute is mandatory.
    Bellow is test csv file i created but does not work:
    10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    The error i am getting while importing this file:
    Missing mandatory field [ip_address] on header line:10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    Assistance appreciated.

    It looks like the IP address field is incorrectly set.,
    It should be as follows
    {Device IP},{Device Subnet Mask}, etc etc
    so a practical example of the aboove could be (i dont know if this is completely correct after the IP address / Subnet Mask)
    10.64.160.31,255.255.255.0,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    below is a link to the documentation
    http://www.cisco.com/en/US/docs/wireless/ncs/1.0/configuration/guide/ctrlcfg.html#wp1840245
    HTH
    Darren

Maybe you are looking for

  • Upgrade to Apex 4.1 results in  "Error processing SSO authentication"

    We recently upgraded our Apex environment to 4.1 from 4.0.2. In our previous environment we used SSO authentication. Some how in the new Apex 4.1 we can get to all our applications with the url https://test.home.org/pls/apex put any application which

  • Need to give file location in FTP Adapter at runtime

    Hi All, We r using FTP Adapter for fetching files from remote server, we have scenario where we need to give the location of file at runtime. Location may vary so the file location must be given at runtime. We r using SOA 11.1.1.3 Thanks, RR Edited b

  • Track changes - Java

    Hello All, I have an application where I have to track the changes made by the user and update the table.The requirement is when a user update/add/delete a field this needs to be inserted in a table with the old and the updated value...I'm thinking o

  • Clear screen

    hi im writing an applet i need it to go to a different screen and im trying not to use card layout heres my code import java.applet.Applet; import java.awt.*; import java.awt.event.*; /* Class illustrates simple Flow Layout of three components. Since

  • TS3989 apple tv photo stream

    I try to log in to Apple TV with my account, and it tells me it is unable to sign in and to go to support/icloud. I find nothing at that location about the issue. Why can't I log in? My password and username are correct. I want to see my photo stream