Skip to content

Commit be805f8

Browse files
committed
feat(library-files): ✨ Added Get-MdeLibraryFiles function
1 parent fa4ff47 commit be805f8

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ jobs:
6464
continue-on-error: true
6565
run: |
6666
[xml]$coverage = Get-Content .\coverage.xml
67-
[int]$covered = $coverage.report.counter | Where-Object type -eq 'INSTRUCTION' | select -ExpandProperty 'covered'
68-
[int]$missed = $coverage.report.counter | Where-Object type -eq 'INSTRUCTION' | select -ExpandProperty 'missed'
67+
[int]$covered = $coverage.report.counter | Where-Object type -eq 'METHOD' | select -ExpandProperty 'covered'
68+
[int]$missed = $coverage.report.counter | Where-Object type -eq 'METHOD' | select -ExpandProperty 'missed'
6969
[int]$sum = $covered + $missed
7070
$coveredPercent = [Math]::Floor(($covered * 100 / $sum) * 100) / 100
7171
$readme = Get-Content ./README.md

src/PSMDE.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
'Get-MdeConfigurationScore'
8585
'Get-MdeExposureScore'
8686
'Get-MdeExposureScoreByMachineGroups'
87+
'Get-MdeLibraryFiles'
8788
'Get-MdeLiveResponseResult'
8889
'Get-MdeMachine'
8990
'Get-MdeMachineAction'

src/public/Get-MdeLibraryFiles.ps1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<#
2+
.SYNOPSIS
3+
List live response library files.
4+
5+
.DESCRIPTION
6+
List live response library files.
7+
8+
.NOTES
9+
Author: Jan-Henrik Damaschke
10+
11+
.LINK
12+
https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/list-library-files?view=o365-worldwide
13+
14+
.EXAMPLE
15+
Get-MdeLibraryFiles
16+
17+
.ROLE
18+
@(@{permission = 'Library.Manage'; permissionType = 'Application'}, @{permission = 'Library.Manage'; permissionType = 'Delegated'})
19+
#>
20+
21+
function Get-MdeLibraryFiles {
22+
[CmdletBinding()]
23+
param ()
24+
Begin {
25+
if (-not (Test-MdePermissions -functionName $PSCmdlet.CommandRuntime)) {
26+
$requiredRoles = (Get-Help $PSCmdlet.CommandRuntime -Full).role | Invoke-Expression
27+
Throw "Missing required permission(s). Please check if one of these is in current token roles: $($requiredRoles.permission)"
28+
}
29+
}
30+
Process {
31+
return Invoke-AzureRequest -Uri "https://api.securitycenter.microsoft.com/api/libraryfiles"
32+
}
33+
End {}
34+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
BeforeAll {
2+
Remove-Module PSMDE -Force -ErrorAction SilentlyContinue
3+
Import-Module (Split-Path $PSCommandPath).replace('tests', 'src').Replace('public', 'PSMDE.psd1')
4+
}
5+
6+
Describe "Get-MdeLibraryFiles" {
7+
8+
It 'Should have the PSMDE module loaded' {
9+
$module = Get-Module PSMDE
10+
$module | Should -Not -BeNullOrEmpty
11+
}
12+
13+
It 'Should have access to internal functions' {
14+
InModuleScope PSMDE {
15+
$cmd = Get-Command Invoke-RetryRequest
16+
$cmd | Should -Not -BeNullOrEmpty
17+
}
18+
}
19+
20+
It 'Should correctly create the request uri' {
21+
InModuleScope PSMDE {
22+
Mock Invoke-AzureRequest { return $uri }
23+
Mock Test-MdePermissions { return $true }
24+
Get-MdeLibraryFiles | Should -Be "https://api.securitycenter.microsoft.com/api/libraryfiles"
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)