我想用两个哈希表创建组
$var_computer = @{
"Notebooks" = "NB";
"PCs" = "PC";
}
$var_os = @{
"Windows10" = "Windows 10*";
"Windows8.1" = "Windows 8.1*";
}
function create_groups ($var_computer, $var_os, $path){
ForEach ($key in ($var_computer).Keys) {
$new_group_name = "_DEFAULT_" + $key
if ((Get-ADGroup -Filter {Name -eq $new_group_name} -SearchBase $path) -eq $null) {
New-ADGroup -name $new_group_name -GroupScope Global -Path $path
}
所以我得到了
_DEFAULT_Notebooks_Windows10
_DEFAULT_Notebooks_Windows8.1
_DEFAULT_PCs_Windows10
...
我如何在$ new_group_name中添加另一个键,以便它不会从我的第二个哈希表中的第一个键开始。 或者嵌套哈希表会更容易吗?
答案 0 :(得分:1)
这是你需要的吗? Foreach OS foreach计算机类型
$var_computer = @{
"Notebooks" = "NB";
"PCs" = "PC";
}
$var_os = @{
"Windows10" = "Windows 10*";
"Windows8.1" = "Windows 8.1*";
}
foreach ($type in $var_computer.Keys) {
foreach ($os in $var_os.Keys) {
$new_group_name = "_DEFAULT_$($type)_$($os)"
$new_group_name
#Create group
}
}
输出:
_DEFAULT_Notebooks_Windows8.1
_DEFAULT_Notebooks_Windows10
_DEFAULT_PCs_Windows8.1
_DEFAULT_PCs_Windows10