PS Newbie here. Just wanted help in the PS excel reading workflow.
I want to do the below tasks using an excel file where I have two sheets.
Create some user-lists
Add Users to user-lists
First sheet has UserLists
Second sheet has users to be added for each user-lists
I wrote the below crude code to do this task. I am able to create the user-list in my integreated document management software but I am not sure how to add users to the user-lists.
$sheet1 = Import-Excel "C:\Users\Me\Desktop\UserList.xlsx" -WorkSheetName "UserList"
foreach($row in $sheet1.rows)
{
$input1 = @{
UserList = $row.Name
UserListDescription = $row.description
}
#Create User List [This part works when run separately]
$userlists = New-PWUserListByName @input1
#Importing Second Sheet [Not sure if it works inside the loop]
$sheet2 = Import-Excel "C:\Users\Me\Desktop\UserList.xlsx" -WorkSheetName "AddUsers"
foreach($column in $sheet2.columns)
{
#Find Users by Name and then Add Users to corresponding User List [**Need Help Here**]
Get-PWUsersByMatch -UserName $column | Add-PWMemberToUserList -UserList $column
}
}
Yeah, my format for AddUsers sheet was wrong. Thanks for correcting this stupid mistake.
I’m creating the list again because I need to use them for “UserList” and “UserListDescription” parameters (@input1)
#Create User List
$userlists = New-PWUserListByName @input1
#Example
$userlists = New-PWUserListByName -UserList 'UserList1' -UserListDescription 'Creating a new userlist1'
Now, the second part of the task needs to get the newly created user-lists and add corresponding users to them.
Below syntax can be used for the purpose.
$FirstValue is the list containing the User Names for the User List in $SecondValue
Again … as we don’t know the cmdlets like New-PWUserListByName, Get-PWUsersByMatch and Add-PWMemberToUserList we’re probably unable to help you really.
Do you have a link to their documentation?
If a cmdlet is named New-PWUserListByName … with "… List … " in it I’d expect you can provide an array of users. So it shouldn’t be necessary to use a loop and provide the users one by one.
It’s working perfectly fine. Just a missing piece, the members in red markup are not added to the user-list. If I keep them in a single cell (“Person1,Person2,Person3”) separated by a comma as you mentioned, I got some error “Cannot find user”.