Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to test PowerShell Auditing Settings via registry #63

Open
matt2005 opened this issue Mar 22, 2019 · 2 comments
Open

Unable to test PowerShell Auditing Settings via registry #63

matt2005 opened this issue Mar 22, 2019 · 2 comments
Labels

Comments

@matt2005
Copy link

When testing for PowerShell auditing settings I am unable to test for the following value as it contains a "*"

The code below is what I'm currently using which doesn't work. I have tried escaping the * by "*" but that doesn't work.

Registry 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames\' "*" { Should -Be '*'}

The problem code is the expandproperty as shown below.

Get-ItemProperty HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames\ | Select-Object -ExpandProperty '*'

Here is the Full Context that I'm using for the PowerShell Audit Settings.

Context -Name 'Powershell Auditing' -Fixture {
        #Turn on Module Logging: Enabled
        Registry 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging\' 'EnableModuleLogging' { Should -BeExactly 1}
        #* Module Names: *
        Registry 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames\' "*" { Should -Be '*'}
        #* Turn on Powershell Script Block Logging:
        #    * Enabled
        Registry 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging\' 'EnableScriptBlockLogging' { Should -Be 1}
        #* Log script block invocation start / stop events:
        #   * Disabled
        IF (Test-Path 'HKLM\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging\EnableScriptBlockInvocationLogging') {
            #If Value doesn't exist it defaults to 0
            Registry 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging\' 'EnableScriptBlockInvocationLogging' {Should -BeLessOrEqual 0}
        }
    }
@matt2005
Copy link
Author

I have created a workaround for my issue by using ".PSObject.Properties.Where{$_.Name -eq '*'}.Value" as shown below.

Context -Name 'Powershell Auditing' -Fixture {
        #Turn on Module Logging: Enabled
        Registry 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging\' 'EnableModuleLogging' { Should -BeExactly 1}
        #* Module Names: *
        #Registry 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames\' "*" { Should -Be '*'}
        It -Name 'Log all modules (ModuleNames: *)' -test {
            (Get-ItemProperty HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames\).PSObject.Properties.Where{$_.Name -eq '*'}.Value | Should -BeExactly '*'
        } 
        #* Turn on Powershell Script Block Logging:
        #    * Enabled
        Registry 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging\' 'EnableScriptBlockLogging' { Should -Be 1}
        #* Log script block invocation start / stop events:
        #   * Disabled
        IF (Test-Path 'HKLM\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging\EnableScriptBlockInvocationLogging') {
            #If Value doesn't exist it defaults to 0
            Registry 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging\' 'EnableScriptBlockInvocationLogging' {Should -BeLessOrEqual 0}
        }
    }

@cdhunt
Copy link
Contributor

cdhunt commented Mar 27, 2019

That is an interesting scenario. I would suggest a new function for testing PowerShell Auditing but 👍 on the workaround. Using an asterisk is an annoying name for a property.

@markwragg markwragg added the bug label Jun 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants