PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
43.66k stars 7.08k forks source link

Add a command which gets the System Lockdown mode information #23799

Open TravisEz13 opened 2 weeks ago

TravisEz13 commented 2 weeks ago

Summary of the new feature / enhancement

We should have a command which gets all the Lockdown mode information. The Lockdown Policy. The current language module and the startup language mode of the session.

> get-lockdowninfo             
LockdownPolicy CurrentLanguageMode InitialLanguageMode
-------------- ------------------- -------------------
None           FullLanguage        FullLanguage

Proposed technical implementation details (optional)

Here is a script which gets the information, but the actual one should be in C#, in PowerShell, so that it works when in lockdown mode.

class LockdownInfo {
    [string]$LockdownPolicy
    [string]$CurrentLanguageMode
    [string]$InitialLanguageMode
    LockdownInfo([string]$policy, [string]$clm, [string]$ilm) {
        $this.LockdownPolicy = $policy
        $this.CurrentLanguageMode = $clm
        $this.InitialLanguageMode = $ilm
    }
}
$spType = [psobject].assembly.GetType("System.Management.Automation.Security.SystemPolicy")
$slpMethod = $spType.GetMethod("GetSystemLockdownPolicy")
$lockdownPolicySetting = $slpMethod.Invoke($null, $null)
$currentLM = $ExecutionContext.Host.Runspace.LanguageMode
$initialLM = $ExecutionContext.Host.Runspace.InitialSessionState.LanguageMode
[LockdownInfo]::new($lockdownPolicySetting, $currentLM, $initialLM)
rhubarb-geek-nz commented 2 weeks ago

If the language modes are unrelated to the system lockdown mode

SystemEnforcementMode GetSystemLockdownPolicy

then I don't see why they should be returned.

Isn't this just a one-liner?

PS> [System.Management.Automation.Security.SystemPolicy]::GetSystemLockdownPolicy()
None

I would suggest it is more related to Get-ExecutionPolicy than languages.

jdhitsolutions commented 2 weeks ago

Submitted for Working Group review

rhubarb-geek-nz commented 1 day ago

I have made a minimalist package for PSGallery from github.