尝试检索域中的域策略和组织单位(OU)时遇到错误。
脚本:
Import-Module GroupPolicy
$forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$domains = $forest.Domains|ForEach-Object { $_.Name }
foreach ($domain in $domains) {
Write-Host "Domain Name: $domain"
# Connect to the domain
$gpmc = New-Object -ComObject "GPMgmt.GPM"
$gpmcDomain = $gpmc.GetDomain($domain)
$gpos = $gpmcDomain.GetGPOs("All")
foreach ($gpo in $gpos) {
Write-Host " GPO Name: $($gpo.DisplayName)"
}
foreach ($ou in $ous) {
Write-Host " OU Name: $($ou.Name)"
}
}
错误类型:
这就是我得到的错误。
PS C:\Users\subhavignesh> C:\testing_gpo.ps1
Domain Name: ngmgmt.internal
Cannot find an overload for "GetDomain" and the argument count: "1"
At C:\testing_gpo.ps1:10 char:5
+ $gpmcDomain = $gpmc.GetDomain($domain)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : RuntimeException
You cannot call a method on a null-valued expression.
At C:\testing_gpo.ps1:11 char:5
+ $gpos = $gpmcDomain.GetGPOs("All")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
1)我需要知道如何连接到IPv6 2)我需要在我的域下输出我的IPv6和GPO策略
1条答案
按热度按时间xzv2uavs1#
你得到的错误意味着方法GetDomain()存在,但是它不只接受一个参数。声明指出了这一点:
当我们查看文档时,我们看到该方法需要三个参数https://learn.microsoft.com/en-us/windows/win32/api/gpmgmt/nf-gpmgmt-igpm-getdomain
在这种特定情况下,此函数始终需要三个参数。当我们只想将域作为参数传递时,我们必须将其他两个参数作为空字符串传递。
顺便说一句,当使用PowerShell中的自动完成功能(Control + Space)时,它还将告诉您哪些方法需要哪些参数。