简体   繁体   English

调用命令错误,尝试通过脚本从 dc 的特定 OU 获取链接的 GPO

[英]Invoke command error, trying to get linked GPO's from specific OU from dc by script

i have a line in PS script which goes to DC and try to do this:我在 PS 脚本中有一行到 DC 并尝试这样做:

    $SWITCH = Invoke-Command -session $s -ScriptBlock {Get-ADOrganizationalUnit -filter *  -Property CanonicalName | Where-Object {$_.CanonicalName -eq $using:listBox2.SelectedItem}}

here are the the variables: $switch = "OU=office,DC=shahar,DC=local" $s = credentials to enter the DC with an admin account.以下是变量: $switch = "OU=office,DC=shahar,DC=local" $s = 使用管理员帐户进入 DC 的凭据。

if i run this line on the DC without the invoke command it works.如果我在没有调用命令的情况下在 DC 上运行这一行,它就可以工作。 if i run other code lines with invoking commands using these credentials it works as well.如果我使用这些凭据运行其他代码行并调用命令,它也可以正常工作。

if i run this line on powershell (not as a part of script) it works.如果我在 powershell 上运行这一行(不是脚本的一部分),它就可以工作。

if i replace $switch with the actual string ("DC=...") it still doesnt work.如果我将 $switch 替换为实际字符串(“DC = ...”),它仍然不起作用。 here is the error and i just cannot figure out whats the problem:这是错误,我只是无法弄清楚问题所在:

Cannot bind parameter 'Identity'.无法绑定参数“身份”。 Cannot convert value "OU=Office,DC=shahar,DC=local" to type "Microsoft.ActiveDirectory.Management.ADOrganizationalUnit".无法将值“OU=Office,DC=shahar,DC=local”转换为类型“Microsoft.ActiveDirectory.Management.ADOrganizationalUnit”。 Error: "Cannot convert the "OU=Office,DC=shahar,DC=local" value of type "Deserialized.Microsoft.ActiveDirectory.Management.ADOrganizationalUnit" to type "Microsoft.ActiveDirectory.Management.ADOrganizationalUnit"."错误:“无法将类型“Deserialized.Microsoft.ActiveDirectory.Management.ADOrganizationalUnit”的“OU=Office,DC=shahar,DC=local”值转换为类型“Microsoft.ActiveDirectory.Management.ADOrganizationalUnit”。” + CategoryInfo: InvalidArgument: (:) [Get-ADOrganizationalUnit], ParameterBindingException + FullyQualifiedErrorId: CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.GetADOrgani zationalUnit + PSComputerName: dc01 + CategoryInfo:InvalidArgument:(:) [Get-ADOrganizationalUnit],ParameterBindingException + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.GetADOrganizationalUnit + PSComputerName:dc01

any help would be much appriciated!任何帮助将不胜感激!

by the way the point of this is to get from the DC the GPO's names that linked to that OU.顺便说一句,这样做的目的是从 DC 获取链接到该 OU 的 GPO 名称。

try this:尝试这个:

ipmo ActiveDirectory,GroupPolicy

$OU = 'OU=office,DC=shahar,DC=local'

(Get-ADOrganizationalUnit $OU).DistinguishedName
$LinkedGPOs = Get-ADOrganizationalUnit $OU | select -ExpandProperty LinkedGroupPolicyObjects
$LinkedGPOGUIDs = $LinkedGPOs | % {$_.Substring(4,36)}
$LinkedGPOGUIDs | % {Get-GPO -Guid $_ | select -ExpandProperty Displayname}

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

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