-
Notifications
You must be signed in to change notification settings - Fork 1
/
SecureAuditor.psm1
59 lines (53 loc) · 1.72 KB
/
SecureAuditor.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
$i18n = Data {
# culture="en-US"
ConvertFrom-StringData @'
RequireAdministrator = Require Administrator
SkipRule = Skip rule
UnsupportedPlatform = Unsupported Platform
'@
}
if ($PSUICulture -ne 'en-US') {
Import-LocalizedData -BindingVariable i18n
}
# https://devblogs.microsoft.com/scripting/use-powershell-to-work-with-any-ini-file/
function Get-IniContent([string]$filePath, [hashtable]$ini = @{}) {
if (-not (Test-Path $filePath -ErrorAction SilentlyContinue)) {
return $ini;
}
switch -regex -file $filePath {
"^\[(.+)\]" {
# Section
$section = $matches[1]
$ini[$section] = if ($null -eq $ini[$section]) { @{} } else { $ini[$section] }
}
"^((;|#).*)$" {
# Comment
continue
}
"(.+?)\s*=\s*(.*)\s*" {
# Key
$name, $value = $matches[1..2]
if ($null -eq $section) {
$section = 'Root'
}
$ini[$section][$name] = $value
}
}
return $ini
}
function IsLocalAdministrator() {
$principal = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if ($principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) {
return $true;
}
return $false;
}
function Write-RequireAdministrator($ruleName) {
Write-Host "`n> $($i18n.SkipRule): $($ruleName) ($($i18n.RequireAdministrator)) ..."
}
function Write-UnsupportedPlatform($ruleName) {
Write-Host "`n> $($i18n.SkipRule): $($ruleName) ($($i18n.UnsupportedPlatform)) ..."
}
function Write-CheckList([bool]$pass, [string]$item) {
Write-Output "- [$(if($pass) {'x'} else {' '})] $($item)"
}