pages

SecurityPolicy – PowerShell Module

SecurityPolicy - PowerShell Module

Description

Provides a way to configure user rights assignments in local security policies using PowerShell without using secedit.exe. This module is alternative to SecurityPolicyDSC which uses a wrapper around secedit.exe. This module is based on LocalSecurityEditor .NET Library.

Supported User Rights Assignment

ConstantNameGroup Policy Setting
SeTrustedCredManAccessPrivilegeAccess Credential Manager as a trusted caller
SeNetworkLogonRightAccess this computer from the network
SeTcbPrivilegeAct as part of the operating system
SeMachineAccountPrivilegeAdd workstations to domain
SeIncreaseQuotaPrivilegeAdjust memory quotas for a process
SeInteractiveLogonRightAllow log on locally
SeRemoteInteractiveLogonRightAllow log on through Remote Desktop Services
SeBackupPrivilegeBack up files and directories
SeChangeNotifyPrivilegeBypass traverse checking
SeSystemtimePrivilegeChange the system time
SeTimeZonePrivilegeChange the time zone
SeCreatePagefilePrivilegeCreate a pagefile
SeCreateTokenPrivilegeCreate a token object
SeCreateGlobalPrivilegeCreate global objects
SeCreatePermanentPrivilegeCreate permanent shared objects
SeCreateSymbolicLinkPrivilegeCreate symbolic links
SeDebugPrivilegeDebug programs
SeDenyNetworkLogonRightDeny access to this computer from the network
SeDenyBatchLogonRightDeny log on as a batch job
SeDenyServiceLogonRightDeny log on as a service
SeDenyInteractiveLogonRightDeny log on locally
SeDenyRemoteInteractiveLogonRightDeny log on through Remote Desktop Services
SeEnableDelegationPrivilegeEnable computer and user accounts to be trusted for delegation
SeRemoteShutdownPrivilegeForce shutdown from a remote system
SeAuditPrivilegeGenerate security audits
SeImpersonatePrivilegeImpersonate a client after authentication
SeIncreaseWorkingSetPrivilegeIncrease a process working set
SeIncreaseBasePriorityPrivilegeIncrease scheduling priority
SeLoadDriverPrivilegeLoad and unload device drivers
SeLockMemoryPrivilegeLock pages in memory
SeBatchLogonRightLog on as a batch job
SeServiceLogonRightLog on as a service
SeSecurityPrivilegeManage auditing and security log
SeRelabelPrivilegeModify an object label
SeSystemEnvironmentPrivilegeModify firmware environment values
SeDelegateSessionUserImpersonatePrivilegeObtain an impersonation token for another user in the same session
SeManageVolumePrivilegePerform volume maintenance tasks
SeProfileSingleProcessPrivilegeProfile single process
SeSystemProfilePrivilegeProfile system performance
SeUndockPrivilegeRemove computer from docking station
SeAssignPrimaryTokenPrivilegeReplace a process level token
SeRestorePrivilegeRestore files and directories
SeShutdownPrivilegeShut down the system
SeSyncAgentPrivilegeSynchronize directory service data
SeTakeOwnershipPrivilegeTake ownership of files or other objects

Installing

Install-Module -Name SecurityPolicy -AllowClobber -Force

Force and AllowClobber aren't necessary but they do skip errors in case some appear.

Updating

Update-Module -Name SecurityPolicy

That's it. Whenever there's a new version you simply run the command and you can enjoy it. Remember, that you may need to close, reopen the PowerShell session if you have already used the module before updating it.

The important thing is if something works for you on production, keep using it till you test the new version on a test computer. I do changes that may not be big, but big enough that auto-update will break your code. For example, small rename to a parameter and your code stops working! Be responsible!

Using SecurityPolicy

Getting and setting Security Policies

$SecurityPolicies = Get-SecurityPolicy -Verbose -All
# $SecurityPolicies | Format-Table

$SecurityPolicies.'Unicode' | Format-Table
$SecurityPolicies.'System Access' | Format-Table
# $SecurityPolicies.'Event Audit' | Format-Table
# $SecurityPolicies.'Registry Values' | Format-Table
# $SecurityPolicies.'Privilege Rights' | Format-Table
# $SecurityPolicies.'Version' | Format-Table

Set-SecurityPolicy -SystemAccess MinimumPasswordAge -Value 1

Getting and setting User Rights Assignment

Adding and removing UserRightsAssignment can be done using Add-UserRightsAssignment and Remove-UserRightsAssignment.

$Output = Get-UserRightsAssignment -UserRightsAssignment SeTrustedCredManAccessPrivilege #-Computer AD1
$Output | Format-Table

Remove-UserRightsAssignment -UserRightsAssignment SeTrustedCredManAccessPrivilege -Identity "S-1-5-21-853615985-2870445339-3163598659-4098"

$Output = Get-UserRightsAssignment -UserRightsAssignment SeTrustedCredManAccessPrivilege #-Computer AD1
$Output | Format-Table

$Output = Get-UserRightsAssignment -UserRightsAssignment SeBackupPrivilege #-Computer AD1
$Output | Format-Table

Add-UserRightsAssignment -UserRightsAssignment SeBackupPrivilege -Identity "Evotec\Administrator"

$Output = Get-UserRightsAssignment -UserRightsAssignment SeBackupPrivilege #-Computer AD1
$Output | Format-Table

Remove-UserRightsAssignment -UserRightsAssignment SeBackupPrivilege -Identity "Evotec\Administrator"

$Output = Get-UserRightsAssignment -UserRightsAssignment SeBackupPrivilege #-Computer AD1
$Output | Format-Table

Or you can use Set-UserRightsAssignment which will add and remove identities for you in one command.

$Output = Get-UserRightsAssignment -UserRightsAssignment SeBackupPrivilege #-Computer AD1
$Output | Format-Table

$Identity = @(
    'BUILTIN\Backup Operators'
    'BUILTIN\Administrators'
    'Guest'
    #'BUILTIN\Users'
    #'przemyslaw.klys'
)

Set-UserRightsAssignment -UserRightsAssignment SeBackupPrivilege -Identity $Identity -WhatIf #-Computer AD1

$Output = Get-UserRightsAssignment -UserRightsAssignment SeBackupPrivilege #-Computer AD1
$Output | Format-Table