none
Powershell script stopped working

    Question

  • A while back I wrote up a powershell script that ran every day and would update certain attributes to AD users.  The script would import a csv with headers, the first header being location which corresponds to the OU the user is in. Next for each location header, or OU it would perform a get-qaduser then set attributes on each user according to the other csv headers. 

    So for example if this was the csv:

    location,street,city,state,zip,CountryCode,co,c
    Somewhereville,1202 North DeadEnd Dr,Dallas,TX,76086,840,United States,US

    Nowheretown,5128 West Long Avenue,Tampa,FL,33634,840,United States,US

    The script would get all users from the Somewhereville OU and set the street, city, state, zip. countrycode, co, and c attributes for each user. it would then move on to all users in the Nowheretown OU and set those attributes.

    Here is the script:

    Add-PSSnapin Quest.ActiveRoles.ADManagement
    import-csv "facilitydetails.csv" -header("location","Street","city","state","zip","CountryCode","co","c") | foreach-object {

    Get-QADUser $_.location -sizelimit 0 | set-qaduser -office $_.location -streetaddress $_.street -l $_.city -st $_.state -postalcode $_.zip -ObjectAttributes @{countryCode=$_.countrycode;co=$_.co;c=$_.c}

    }

    This was working flawlessly for a long time now recently it has come to my attention it is no longer working.  I have broken it up to test different parts. For example if I put in powershell 

    import-csv "facilitydetails.csv" -header("location","Street","city","state","zip","CountryCode","co","c") | foreach-object {

    ECHO $_.location

    It displays in a list all the values under the location header so I know the foreach portion is working properly

    The issue is 2 things, it no longer returns all users and seems to pick out the ones it wants. Secondly it is not writing the office attribute attribute anymore.  I have troubleshot this for 2 days and am at a loss right now.  If anyone has any ideas or advice please share.  Thank you.


    • Edited by AuthenticX Friday, December 9, 2016 4:17 PM typo
    Friday, December 9, 2016 4:16 PM

All replies

  • I have never used the Quest cmdlets, but the script makes little sense to me. If $_.location is the RDN of an OU, it cannot be used to retrieve the users in the OU.

    Get-QADUser $_.location -sizelimit 0

    The RDN (the Relative Distinguished Name) does not uniquely identify any object in AD. Or are your "Somewhereville" and "Nowheretown" actually the distinguished names of the OU's (in which case they must be quoted in the CSV)?

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)


    Saturday, December 10, 2016 1:30 AM