如何使用 Powershell 将 QOS 添加到本地计算机策略

如何使用 Powershell 将 QOS 添加到本地计算机策略

我有此代码,它可以运行,但它会生成域 GPO 策略,而不是本地策略。我如何将其变为本地策略?

#Create QOS for RDP Session
#Create a new Group Policy Object (GPO) that will be applied to the LocalHost that contain the computer objects.
#The value "Teams client - QoS" can be modified to fit your needs or naming standards
New-GPO "Local Computer Policy"  -Name "MSTSC" -Comment "QoS for Agents."

#Create Registry Value for Teams client Audio QoS in the "Teams Client - QoS" GPO
Set-GPRegistryValue -Name "MSTSC" -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows\QoS\MSTSC" -ValueName "Application Name", "DSCP Value", "Local IP", "Local IP Prefix Length", "Local Port", "Protocol", "Remote IP", "Remote IP Prefix Length", "Remote Port", "Throttle Rate", Version -Type String -Value "mstsc.exe", "0", "*", "*", "*", "*", "*", "*", "*", "-1", "1.0"

答案1

至于这个..

“制定域 GPO 策略,而不是本地策略”

这是设计使然。PowerShell 中没有本地 GPO 的 cmdlet,因此,您必须自己编写它,或者使用此模块

策略文件编辑器:

请参阅本文了解其用途:如何使用 Powershell 管理本地组策略

此模块可用于管理本地策略,但也可用于从策略模板中获取策略。例如,安全合规性管理器附带的策略模板。如果您还想为本地策略设置基准,则可以使用此模块将实时策略与模板中的策略进行比较。如果策略发生变化,则可以轻松返回并进行单一更改。在下面的屏幕截图中,您可以看到 SCM Windows 10 用户策略的 Get-PolicyFileEntry 的输出。

答案2

我无法将其放入 GPO,但我可以将其添加到注册表

# Setup QOS on MSTSC session

# Works but doesn't show up in GPO Editor
#reg import .\MSTSC.reg

# Works but doesn't show up in GPO Editor
# Invoke-Command {reg import .\MSTSC.reg *>&1}

# Works but doesn't show up in GPO Editor
$StartParams = @{
FilePath = "$Env:SystemRoot\REGEDIT.exe"
ArgumentList = '/s','.\MSTSC.reg'
Verb = 'RunAs'
PassThru = $True
Wait = $True
}
$Proc = Start-Process @StartParams

If ($Proc.ExitCode -eq 0) { Write-Host 'Success!' }
Else { Write-Host "Fail! Exit code: $($Proc.ExitCode)" }

Pause

相关内容