简体   繁体   English

从2个csv文件循环问题中复制GPO

[英]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. 我有2个csv文件,一个具有Win7 GPO的显示名称,另一个具有Win10的显示名称。 I want to loop through both csv so that I can copy the GPO settings from Win7 to a new Win10 display name GPO. 我要遍历两个csv,以便可以将GPO设置从Win7复制到新的Win10显示名称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. 当我运行循环时,它将相同的第一个win7 GPO应用于所有新的Win10 GPO,然后将第二个以此类推...等等,我环顾四周,但似乎无法获得提示。 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. 如果您的CSV文件包含完全相同的行数,并且一个文件中的每一行都与另一文件中的同一行号相对应,则可以使用for循环。

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 . 如果CSV文件包含标题,则需要引用该标题属性,例如$Win7GPO[$i].Property

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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