我有这组代码:
#Find the OU with the selected Canonical name and save it to this variable
$OUObject = Invoke-Command -Session $S -ScriptBlock {Get-ADOrganizationalUnit -filter * -Property CanonicalName | Where-Object {$_.CanonicalName -eq $using:listBox2.SelectedItem}}
因此,在此代码之后,我得到了一个存储在变量$ OUObject中的OU。我现在想获取与此ou相关的所有gpo。所以我的下一步是:
$test = $OUObject.LinkedGroupPolicyObjects
现在$ test保留与其ou链接的所有gpos。现在的问题是我想按名称命名。所以我可以这样做:
invoke-command -session $s -scriptblock {get-gpo -guid $test}
但是我会收到此错误:PS C:\ WINDOWS \ system32> invoke-command -session $ s -scriptblock {get-gpo -guid $ test}无法验证参数“ Guid”上的参数。参数为null或为空。提供一个不为null或为空的参数,然后重试该命令。+ CategoryInfo:InvalidData:(:) [Get-GPO],ParameterBindingValidationException+ FullyQualifiedErrorId:ParameterArgumentValidationError,Microsoft.GroupPolicy.Commands.GetGpoCommand+ PSComputerName:DC01
所以我看一下$ test,这就是它的含义:
PS C:\WINDOWS\system32> $test
cn={5873971D-F689-4E83-8AFA-389FDD7F34CD},cn=policies,cn=system,DC=bla,DC=local
cn={2B7F8931-038E-46BC-B1DB-FBFA86097C08},cn=policies,cn=system,DC=bla,DC=local
cn={C74CADA1-B609-44A3-8D3C-F733CF3112E2},cn=policies,cn=system,DC=bla,DC=local
所以我真正需要的是仅将cn {..}中的部分粘贴到get-gpo命令中>
例如,如果我进行硬编码,并执行此操作:
invoke-command -session $s -scriptblock {get-gpo -guid 5873971D-F689-4E83-8AFA-389FDD7F34CD}
我得到正确的结果。有人可以帮我实现这个吗?
我有这组代码:#查找具有所选规范名称的OU并将其保存到此变量$ OUObject = Invoke-Command -Session $ S -ScriptBlock {Get-ADOrganizationalUnit -filter * -...
使用正则表达式-replace
运算符从DN中提取GUID,然后使用Invoke-Command
修饰符将值传递给$using:
: