Clearing users with certain UPN

Currently I have a list of users with a certain upn @oldomain.com. However the list also contains users with the new UPN @NewDomain1.com, @NewDomain2.com and @newDomain3.com

What i Want to do is import that list any user with @OldDomain.com i want to clear the attribute completly. However any user with the @newdomain1,2 and 3.com to leave it alone. The other portion of my problem is these users are on the 3 different domains. so I want it to cycle through. I'm also using QAD Cmdlets, this is what i have so far

add-pssnapin quest.activeroles.admanagement

$Domains = @(  
'newdomain1.com'
'newdomain2.com'
'newdomain3.com'
)

$Domains |%{ $domain = $_

import-csv .\Test.csv | foreach-object{Get-QADUser -service $_ -Identity {$_.samaccountname} | where {$_.userprincipalName -like '*@oldomain.com'} |`
set-qaduser -objectAttributes @{userPrincipalName=$null}}

}

Open in new window


The error i receive is:
Get-QADUser : Cannot evaluate parameter 'Identity' because its argument is
specified as a script block and there is no input. A script block cannot be
evaluated without input.
At C:\Users\user1\Documents\UpdateUserUPNv2.ps1:16 char:50
+ foreach-object{Get-QADUser -service $_ -Identity {$_.samaccountname} | where
{$_ ...
+                                                  ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (:) [Get-QADUser], ParameterBindi
   ngException
    + FullyQualifiedErrorId : ScriptBlockArgumentNoInput,Quest.ActiveRoles.Ars
   PowerShellSnapIn.Powershell.Cmdlets.GetUserCmdlet
LVL 1
ntr2defAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
Why not try something like below...
Import-Module activedirectory
$FindUPN = Import-Csv "c:\test.csv"
ForEach ($User in $FindUPN) 
        {
            
            Get-ADUser -Identity $User.UPN -Properties sAMAccountName, UserPrincipalName

        If ($User.UserPrincipalName -like "*@olddomain.com") 

        {

            Set-ADUser -Identity $User.sAMAccountName -UserPrincipalName $null

     } else {

            Write-Output "$User.UPN has NOT been modified"   

     }



}

Open in new window


The CSV needs to have a Column Heading titled UPN for the above script to work. Run this in a test lab first or with a single user, as i have not tested this myself.

Will.
0
ntr2defAuthor Commented:
well its a multi-domain environment and needs to cycle through the domains to find the users, so this will not work
0
Will SzymkowskiSenior Solution ArchitectCommented:
Are these domains child domains within the same forest or do you have forest trusts and each domain is a forest root domain?

Also, if you only want to modify the olddomain.com UPN why do you need to query againts all of them?

Will.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ntr2defAuthor Commented:
Sorry i meant multi forest, they have a trust between each root domain.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.