I've list of PW users which needs to be added to UserList.
I've read the help about Add-PWUserToUserList, it requires -InputUser parameter as array of user object.
To get the array of users I tried Get-PWusersbymatch -Email '*@xyz.com' cmdlet but it shows all the users. I do not want to add all of them.
Is there any other cmdlet I can use to make array of user object ?
Any suggestion would be helpful.
shows all the users with email of xyz.com or all the users in the datasource? If you do:
$l1 = Get-PWUsersByMatch -email '*@xyz.com'
$l2 = Get-PWUsersByMatch
are the count's the same? In my testing the first one only returns accounts with email addresses ending with @xyz.com while the second returns a lot more accounts.
Is the list you have in a text file or something?
Also you can use the -Username option with Add-PWUserToUserList if you have those. It accepts an array so this works:
Add-PWUsertoUserList -UserName 'user1','user2','user3'
Thanks Brandon and Kevin for your inputs and my apology for not writing correct situation.
There are almost 500 PW users with account id @xyz.com and I would like to add only 50 pw users to UserList.
The list can be available in csv or xlsx or text format.
If you put each email address in a text file, one per line you can do:
$users = Get-Content -Path 'path/to/file.txt'
Get-PWUsersByMatch -email $users | Add-PWUsersToUserList -UserList 'UserList Name'
Answer Verified By: Aniruddh Chavan
Thanks a lot Kevin !! it worked.
In the meantime, I tried with Import-CSV cmdlet but that didn't help.
One more thing I noticed that there should not be any blank spaces, blank lines in text file otherwise PowerShell simply throughs error. Something like - can not validate parameter "Email"
Get-Content returns an array where each array element is a line from the file. Blank lines go in as empty strings. So when Get-PWUsersByMatch processes the array of users it sees an empty string and throws an error that it doesn't match an email address.
you can fix by adding some code after Get-Content to only use lines that aren't empty.