MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "New-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') {4 5 BeforeAll {6 $defaultParamValues = $PSDefaultParameterValues.Clone()7 $IsNotSkipped = ($IsWindows -and !$IsCoreCLR)8 $PSDefaultParameterValues["it:skip"] = !$IsNotSkipped9 }10 11 AfterAll {12 $global:PSDefaultParameterValues = $defaultParamValues13 }14 15 BeforeEach {16 if ($IsNotSkipped) {17 Remove-EventLog -LogName TestLog -ErrorAction Ignore18 }19 }20 21 It "should be able to create a New-EventLog with a -Source parameter" -Skip:($true) {22 {New-EventLog -LogName TestLog -Source TestSource -ErrorAction Stop} | Should -Not -Throw23 {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventId 1 -ErrorAction Stop} | Should -Not -Throw24 $result=Get-EventLog -LogName TestLog25 $result.Count | Should -Be 126 }27 It "should be able to create a New-EventLog with a -ComputerName parameter" -Skip:($true) {28 {New-EventLog -LogName TestLog -Source TestSource -ComputerName $env:COMPUTERNAME -ErrorAction Stop} | Should -Not -Throw29 {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventId 1 -ErrorAction Stop} | Should -Not -Throw30 $result=Get-EventLog -LogName TestLog31 $result.Count | Should -Be 132 $result.EventID | Should -Be 133 }34 It "should be able to create a New-EventLog with a -CategoryResourceFile parameter" -Skip:($true) {35 {New-EventLog -LogName TestLog -Source TestSource -CategoryResourceFile "CategoryMessageFile" -ErrorAction Stop} | Should -Not -Throw36 {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventId 2 -ErrorAction Stop} | Should -Not -Throw37 $result=Get-EventLog -LogName TestLog38 $result.Count | Should -Be 139 $result.EventID | Should -Be 240 }41 It "should be able to create a New-EventLog with a -MessageResourceFile parameter" -Skip:($true) {42 {New-EventLog -LogName TestLog -Source TestSource -MessageResourceFile "ResourceMessageFile" -ErrorAction Stop} | Should -Not -Throw43 {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventId 3 -ErrorAction Stop} | Should -Not -Throw44 $result=Get-EventLog -LogName TestLog45 $result.Count | Should -Be 146 $result.EventID | Should -Be 347 }48 It "should be able to create a New-EventLog with a -ParameterResourceFile parameter" -Skip:($true) {49 {New-EventLog -LogName TestLog -Source TestSource -ParameterResourceFile "ParameterMessageFile" -ErrorAction Stop} | Should -Not -Throw50 {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventId 4 -ErrorAction Stop} | Should -Not -Throw51 $result=Get-EventLog -LogName TestLog52 $result.Count | Should -Be 153 $result.EventID | Should -Be 454 }55}56 