如何在计算机管理中隐藏或删除本地用户和组

时间:2017-07-13 15:05:34

标签: powershell

我可以使用Powershell从计算机管理中删除或隐藏本地用户和组吗? 我知道我可以为组策略执行此操作,但我想从Powershell为特定用户执行此操作。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

这将做你想要的。请注意,通过组策略执行此操作将覆盖您手动设置的内容。

我添加了一个小的TUI(文本用户界面)选项。

更好地解释代码。在基本版本中,它将MMC的注册表项从0更改为1.这些函数将禁用或启用MMC,但菜单系统会询问您要执行的操作。

正如您所说,您知道如何使用GPO执行此操作,但GPO实际上使用了名为-value 1的其他DWORD。如果在PowerShell脚本之前或之后设置此值将忽略(User Configuration\Administrative Templates\Windows Components\Microsoft Management Console\Restricted/Permitted snap-ins)

本地用户和群组

(HKCU\Software\Policies\Microsoft\MMC\{5D6179C8-17EC-11D1-9AA9-00C04FD8FE93})

Restrict_Run

##  Computer Management Values
##  Value = 0 (or not in registry) The policy is disabled or not configured. Users can open the MMC in Author mode.
##  Value = 1 The policy is enabled. Users cannot open the MMC in Author mode.

Function Disable_MMC_Computer_Management
{
New-ItemProperty -PropertyType "Registry::HKEY_CURRENT_USER\Software\Policies\Microsoft\MMC\{5D6179C8-17EC-11D1-9AA9-00C04FD8FE93}" -Value "1"
}
Function Enable_MMC_Computer_Management
{
New-ItemProperty -PropertyType "Registry::HKEY_CURRENT_USER\Software\Policies\Microsoft\MMC\{5D6179C8-17EC-11D1-9AA9-00C04FD8FE93}" -Value "0"
}

Function MMC_Computer_Management
{
Write-Host "`n Menu System:" -Fore Cyan
[int]$global:Menu = 0
while ( $global:Menu -lt 1 -or $global:Menu -gt 3 ){
Write-host "1. Disable MMC Computer Management" -Fore Cyan
Write-host "2. Enable MMC Computer Management" -Fore Cyan
Write-host "3. Exit" -Fore Cyan
[Int]$global:Menu = read-host "Choose an option 1 to 4" }
Switch( $global:Menu ){
1{Disable_MMC_Computer_Management}
2{Enable_MMC_Computer_Management}
3{Exit}
}
    }
    MMC_Computer_Management

import {Map, GoogleApiWrapper} from 'google-maps-react'