Nov 04 2021 11:47 AM
Hello all
I have the below script. What i am trying to accomplish is this. below.
csv file contains list of users (upn)
PowerShell script reads all users from csv file (step1.) does a compare or hash table against users in three specific OU's in AD using (upn). The three specific OU's contain all of our vendor accounts
If a match is found, extend account expiration + 90 days
if a match is not found write the non matched accounts to a separate .csv file
However i am getting the following error
"Get-ADUser : Error parsing query: 'userPrincipalName -eq @{userprincipalname=Akhil.Gattu@mydomain.com}.UPN' Error Message: 'syntax error' at position: '23'.
At line:4 char:15
+ ... $u = Get-ADUser -Filter "userPrincipalName -eq $_.UPN" -Proper ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Get-ADUser], ADFilterParsingException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Microsoft.ActiveDirectory.Management.Commands.GetADUser"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Script
Nov 04 2021 12:07 PM - edited Nov 04 2021 01:12 PM
Hi,
The problem might be the way you are getting the UPN value and the single quotes
Maybe you want to try with
Get-ADUser -Filter "userPrincipalName -eq '$_.UPN'"
You can also take a look at this script of mine where I do a similar thing
https://github.com/get-itips/M365EnterpriseDemoCustomizer/blob/dev/Customize-M365EnterpriseDemo.ps1
Do you have a column name in the CSV named UPN right?
Edit: Typo 😉
Nov 04 2021 02:27 PM