EDIT: I think I solved it?
$dir = "H:\ScriptLibrary\KB4_Users_Target\KB4Users*"
$filter = "*.csv"
$latest = Get-ChildItem -Path $dir -Filter $filter | Sort-Object
LastAccessTime -Descending | Select-Object -First 1
$list = Get-content $latest
$strGroupName = "CN=Eddie Play
Ground,OU=TestAccounts,OU=GlobalApps,DC=global,DC=scj,DC=loc"
Foreach($user in $list)
{add-qadgroupmember -identity $strGroupName -member $user}
But now am getting an access denied error, which is something on our side I need to dive into.
I am trying to import the newest csv file (users list) and add them to a known QAD security group. The newest file will be uploaded daily and I want to automate a script in QAD to add the new users to the target group. What I have so far is this and I've been all over and keep getting different recommendations and am stuck here. The last part of the script populates the group just fine, I am just trying to get the newest list from the file location and import that CSV.
Ideally, I would then like to move that file I imported to a subfolder where it is hosted (D:\Scripts\KB$\KB4Processed)
$dir = "D:\Scripts\KB4
#$list = Get-content D:\Scripts\KB4\KB4Users*"
$filter = "*.csv"
$latest = Get-ChildItem -Path $dir -Filter $filter | Sort-Object
LastWriteTime -
Descending | Select-Object -First 1
$latest.Name $OutFile = 'D:\Scripts\KB4\KB4USersProcess.csv'
Import-Csv -Path $latest | ForEach-Object {
$strGroupName =
"CN=.GroupName,OU=DistributionGroups,DC=global,DC=mydomain,DC=loc"
$list =D:\Scripts\KB4\KB4USersProcess.csv
Foreach($user in $list)
{add-qadgroupmember -identity $strGroupName -member $user}`
I am expecting to import the latest file of users and then add them to a QAD group
SOLVED:
I was able to edit the files and target only the one with the most recent updates and then add them to the group I needed to.