Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Foreach logic question

$
0
0

I have a CSV that has the following column headings:

UserIDNameGroupNameLogonRestrictions

 

UserID is the sAMAccountName.

GroupName is the name of an AD group

LogonRestrictions is a machine name.

My current script is as follows:

$inputFile = "\\NP1SECR016v\SECRpt\LogonRestrictionConfig\SSLVPN_Users.csv"

$complist = Import-Csv -Path $inputFile | ForEach-Object {$_.Logonrestrictions} 

foreach($comp in $complist){ 

$comparray += ","+$comp 

Set-ADUser -Identity "H139616" -LogonWorkstations $comparray

#End Script

 

this works great if all the records are for the same UserID. However, the csv that I am given has multiple user accounts. In other words the first 10 records will be for userA with a unique logonrestriction value (10 unique computer names). The next 20 records will be for user B with an entirely different list of computer names. I have like 27 unique user IDs and the total record count is 1800.

 

Is there a clever way to built the $comparray for the first unique user ID then run the set-aduser command and then build the $comparray for the next unique user ID and so on and so on?


Viewing all articles
Browse latest Browse all 6937

Trending Articles