[英]Import-GPO by using folders named after its DisplayName - Powershell
I am using a powershell script to import GPOs which I have saved as GUIDs (the default).我正在使用 powershell 脚本导入已保存为 GUID(默认值)的 GPO。
I wish to import the GPOs on a different system, the GPOs are saved to a CD at this point.我希望在不同的系统上导入 GPO,此时 GPO 已保存到 CD。 So a simple way to import a single GPO would be:
因此,导入单个 GPO 的简单方法是:
$domain=[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name
$import_array = get-childitem ($current_drive + $gpo_backup_location) | Select name
foreach ($GPO in $import_array) {
Import-GPO |
-backupgponame $GPO.name -path ($Current_Drive + $gpo_backup_location) |
-domain $domain |
-Targetname $GPO.name |
-migrationtable ($Current_drive + $mig_table_path) |
-Createifneeded;
}
}
the $import_array command gives me my folder names $import_array 命令给了我我的文件夹名称
Name
----------
GPO-1
GPO-2
GPO-3
GPO-4
and so on...
I want to iterate over these and import each one.我想遍历这些并导入每一个。 The GPOs are saved using another block of code to backup the GPOs as their displayname.
使用另一个代码块保存 GPO,将 GPO 备份为它们的显示名称。 (GPO-1, GPO-2, etc.,)
(GPO-1、GPO-2 等)
I cannot for the life of me figure out how to force it to look at the folder name and to import these我一生都无法弄清楚如何强制它查看文件夹名称并导入这些
The Backup was created with the following code:备份是使用以下代码创建的:
Function GPO_Backup_DisplayName ($MenuChoice) {
write 'Backing Up GPOs by Display Name'
Foreach ($GPO in $GPO_Temp_Backup) {
$GPOBackup = Backup-GPO `
-name $GPO.DisplayName `
-path ($Current_drive + $GPO_Backup_Location) `
-Domain $domain;
Get-GPOReport $GPO.DisplayName `
-reporttype HTML `
-Domain $domain `
-path ($Current_drive + $GPO_Backup_HTML_Report + $GPO.DisplayName + ".html");
Rename-item
-path ($Current_drive + $GPO_Backup_Location + "{" + $GPOBackup.Id + "}") `
-newname $GPO.DisplayName
}
}
If you export each GPO to its own folder and name that folder after the GPO, you can iterate over these folders in a foreach
loop to import the GPOs and set the target name to the folder name.如果将每个 GPO 导出到其自己的文件夹并以 GPO 命名该文件夹,则可以在
foreach
循环中遍历这些文件夹以导入 GPO 并将目标名称设置为文件夹名称。 Something like this should work:这样的事情应该工作:
Get-ChildItem "C:\backup" | % {
$name = $_.name
$id = (get-childitem $_) -replace '[{}]', ''
Import-GPO -BackupId $id -TargetName $name -path $_.Path -CreateIfNeeded
}
Prerequisite is that you created the backups with something like this:先决条件是您使用以下内容创建了备份:
Get-GPO -All | % {
$name = $_.DisplayName
$dir = New-Item "C:\backup\$name" -Type Directory
Backup-GPO -Guid $_.Id -Path $dir
}
Also, the backup directory should contain only the folders with the single GPO backups, otherwise you'll have to add a filter between Get-ChildItem
and ForEach-Object
.此外,备份目录应仅包含具有单个 GPO 备份的文件夹,否则您必须在
Get-ChildItem
和ForEach-Object
之间添加过滤器。
使用 PowerShell 列出组策略对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.