Windows 10 上的组策略中缺少 Powershell Set/Get-GPPermission

Windows 10 上的组策略中缺少 Powershell Set/Get-GPPermission

最近从 Windows 7 企业版更新到 Windows 10 企业版,并运行一个调用 Get-GPPermision 的脚本,但因缺少该命令而出错。编辑:Set-GPPermission 也丢失了。

检查组策略 cmdlet 中的命令表明确实缺少该命令:

PS C:\WINDOWS\system32> get-command -Module grouppolicy

CommandType     Name                                               Version    Source                                             
-----------     ----                                               -------    ------                                             
Cmdlet          Backup-GPO                                         1.0.0.0    GroupPolicy                                        
Cmdlet          Copy-GPO                                           1.0.0.0    GroupPolicy                                        
Cmdlet          Get-GPInheritance                                  1.0.0.0    GroupPolicy                                        
Cmdlet          Get-GPO                                            1.0.0.0    GroupPolicy                                        
Cmdlet          Get-GPOReport                                      1.0.0.0    GroupPolicy                                        
Cmdlet          Get-GPPrefRegistryValue                            1.0.0.0    GroupPolicy                                        
Cmdlet          Get-GPRegistryValue                                1.0.0.0    GroupPolicy                                        
Cmdlet          Get-GPResultantSetOfPolicy                         1.0.0.0    GroupPolicy                                        
Cmdlet          Get-GPStarterGPO                                   1.0.0.0    GroupPolicy                                        
Cmdlet          Import-GPO                                         1.0.0.0    GroupPolicy                                        
Cmdlet          New-GPLink                                         1.0.0.0    GroupPolicy                                        
Cmdlet          New-GPO                                            1.0.0.0    GroupPolicy                                        
Cmdlet          New-GPStarterGPO                                   1.0.0.0    GroupPolicy                                        
Cmdlet          Remove-GPLink                                      1.0.0.0    GroupPolicy                                        
Cmdlet          Remove-GPO                                         1.0.0.0    GroupPolicy                                        
Cmdlet          Remove-GPPrefRegistryValue                         1.0.0.0    GroupPolicy                                        
Cmdlet          Remove-GPRegistryValue                             1.0.0.0    GroupPolicy                                        
Cmdlet          Rename-GPO                                         1.0.0.0    GroupPolicy                                        
Cmdlet          Restore-GPO                                        1.0.0.0    GroupPolicy                                        
Cmdlet          Set-GPInheritance                                  1.0.0.0    GroupPolicy                                        
Cmdlet          Set-GPLink                                         1.0.0.0    GroupPolicy                                        
Cmdlet          Set-GPPrefRegistryValue                            1.0.0.0    GroupPolicy                                        
Cmdlet          Set-GPRegistryValue                                1.0.0.0    GroupPolicy      

以下是版本表:

PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value                                                                                             
----                           -----                                                                                             
PSVersion                      5.1.14393.693                                                                                     
PSEdition                      Desktop                                                                                           
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                           
BuildVersion                   10.0.14393.693                                                                                    
CLRVersion                     4.0.30319.42000                                                                                   
WSManStackVersion              3.0                                                                                               
PSRemotingProtocolVersion      2.3                                                                                               
SerializationVersion           1.1.0.1

我能找到的最新命令(上个月发布)显示该命令仍然存在:https://technet.microsoft.com/itpro/powershell/windows/group-policy/index

注意:微软似乎已经破坏了向后兼容性,因为在 powershell 4 的组策略中,调用被命名为 Get-GPPermissions 和 Set-GPPermissions,现在它们删除了“s”,并且都命名为单数 Get-GPPermission 和 Set-GPPermission。

有人知道我如何重新安装该模块吗?

编辑:模块重新安装很容易,只需卸载 RSAT 然后重新安装即可。遗憾的是,命令仍然没有显示,所以我的问题现在应该是如何恢复丢失的命令。

答案1

在花了太多时间尝试调试这个问题后,我放弃了,并从头开始重新镜像系统,解决了这个问题。这不是答案,但它使问题变得毫无意义。

答案2

我假设你正在使用 Win10 客户端(带有 RSAT?)来写下你的脚本。我建议导入组策略来自 DC PSSession 的模块:

$DC = 'yourDomainController'
$Credentials = Get-Credentials 
$DCSession = New-PSSession -ComputerName $DC -Credential $Credentials
Import-Module grouppolicy -PSSession $DCSession

##############

Get-Command -Module grouppolicy

CommandType     Name                                               Version    
Source                                                                                                                                                                 
-----------     ----                                               -------    -- 
Function        Backup-GPO                                         1.0        grouppolicy                                                                                                                                                            
Function        Copy-GPO                                           1.0        grouppolicy                                                                                                                                                            
Function        Get-GPInheritance                                  1.0        grouppolicy                                                                                                                                                            
Function        Get-GPO                                            1.0        grouppolicy                                                                                                                                                            
Function        Get-GPOReport                                      1.0        grouppolicy                                                                                                                                                            
Function        Get-GPPermissions                                  1.0        grouppolicy                                                                                                                                                            
Function        Get-GPPrefRegistryValue                            1.0        grouppolicy                                                                                                                                                            
Function        Get-GPRegistryValue                                1.0        grouppolicy                                                                                                                                                            
Function        Get-GPResultantSetOfPolicy                         1.0        grouppolicy                                                                                                                                                            
Function        Get-GPStarterGPO                                   1.0        grouppolicy                                                                                                                                                            
Function        Import-GPO                                         1.0        grouppolicy                                                                                                                                                            
Function        New-GPLink                                         1.0        grouppolicy                                                                                                                                                            
Function        New-GPO                                            1.0        grouppolicy                                                                                                                                                            
Function        New-GPStarterGPO                                   1.0        grouppolicy                                                                                                                                                            
Function        Remove-GPLink                                      1.0        grouppolicy                                                                                                                                                            
Function        Remove-GPO                                         1.0        grouppolicy                                                                                                                                                            
Function        Remove-GPPrefRegistryValue                         1.0        grouppolicy                                                                                                                                                            
Function        Remove-GPRegistryValue                             1.0        grouppolicy                                                                                                                                                            
Function        Rename-GPO                                         1.0        grouppolicy                                                                                                                                                            
Function        Restore-GPO                                        1.0        grouppolicy                                                                                                                                                            
Function        Set-GPInheritance                                  1.0        grouppolicy                                                                                                                                                            
Function        Set-GPLink                                         1.0        grouppolicy                                                                                                                                                            
Function        Set-GPPermissions                                  1.0        grouppolicy                                                                                                                                                            
Function        Set-GPPrefRegistryValue                            1.0        grouppolicy                                                                                                                                                            
Function        Set-GPRegistryValue                                1.0        grouppolicy 

您可以自动定义凭证。请访问:https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/add-credentials-to-powershell-functions?view=powershell-5.1

相关内容