简体   繁体   中英

copy GPO from 2 csv files loop issue

I have 2 csv files, one with the Win7 GPOs display name and another with the Win10 display name. I want to loop through both csv so that I can copy the GPO settings from Win7 to a new Win10 display name GPO. When I run my loop, it applies the same 1st win7 GPO to all new Win10 GPOs, then the second etc... I've looked around but I can't seem to get a tip. Any help would be appreciated.

import-module grouppolicy
import-module activedirectory

$Win7GPOPath = "c:\temp\copyWin7GPOs.csv"
$Win10GPOPath = "c:\temp\copyWin10GPOs.csv"

$7GPO = @{}
$10GPO = @{}

$Win7GPO = import-csv $Win7GPOPath
$Win10GPO = import-csv $Win10GPOPath

ForEach($7GPO in $Win7GPO) {


    ForEach($10GPO in $Win10GPO) {

    Write-Output "Copy-GPO -SourceName $7GPO -TargetName $10GPO"
          }
    }

If your CSV files contain the exact same number of rows and each row in one file corresponds to that same row number in the other file, you can use one for loop.

import-module grouppolicy
import-module activedirectory

$Win7GPOPath = "c:\temp\copyWin7GPOs.csv"
$Win10GPOPath = "c:\temp\copyWin10GPOs.csv"

$7GPO = @{}
$10GPO = @{}

$Win7GPO = import-csv $Win7GPOPath
$Win10GPO = import-csv $Win10GPOPath

for ($i = 0; $i -lt $Win7GPO.count; $i++) {
   Copy-GPO -SourceName $Win7GPO[$i] -TargetName $Win10GPO[$i]
}

If the CSV file contains a header, you will need to reference that header property like $Win7GPO[$i].Property .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM