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

how to BREAK while looping through files ?

$
0
0

We have a login script that will map your drives based on AD group membership. We are trying to find out some information about users G: drives. We have 64 different GDrive AD groups. So you can have your G: drive mapped to 64 different places based on what group you are in. I wrote this script to get all of the groups:

Get-ADGroup -Filter {name -like "mg.g_drive*"} | Select-Object name | out-file c:\temp\GDrive.txt

This worked and I then had a list of all 64 groups.

Now in the code below I need to read all 64 .TXT files which I can do. But..... How do I "BREAK" at the end each .txt file and then
do my out-file on each .txt file? So I would have 64 output files.



Clear-Host
Foreach ($fileinGet-Childitem C:\temp\AD2)
{ $GivenName=get-content$file.name
foreach ($Userin$GivenName) {(Get-ADUser-ldapfilter"(displayname=$user)"-Property*).samaccountname | out-file c:\temp\ad2\masterlist.txt-Append}
}


Viewing all articles
Browse latest Browse all 6937

Trending Articles