-
Notifications
You must be signed in to change notification settings - Fork 1
/
rqmt-testers.psm1
86 lines (69 loc) · 2.67 KB
/
rqmt-testers.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
$ErrorActionPreference = "Stop"
Import-Module "$PSScriptRoot\common-utils.psm1" -Force
Import-Module "$PSScriptRoot\network-utils.psm1" -Force
Import-Module "$PSScriptRoot\value-testers.psm1" -Force
Function Test-HardwareNotCompatible {
$HyperVInfo = Get-ComputerInfo -Property "*Hyper*"
# If Hyper-V is already enabled, the hardware is compatible.
If ($HyperVInfo.HyperVisorPresent) {
Return $False
}
$HyperVRequirements = (
"HyperVRequirementDataExecutionPreventionAvailable",
"HyperVRequirementSecondLevelAddressTranslation",
"HyperVRequirementVirtualizationFirmwareEnabled",
"HyperVRequirementVMMonitorModeExtensions"
)
ForEach ($Requirement In $HyperVRequirements) {
If (!($HyperVInfo.$Requirement)) {
Return $True
}
}
Return $False
}
Function Test-HyperVNotEnabled {
$HyperV = Get-WindowsOptionalFeature -FeatureName "Microsoft-Hyper-V-All" -Online
Return ($HyperV.State -Ne "Enabled")
}
Function Test-NamesAvailable($TakenNames, $NamesToTest) {
Test-ValueIsArray $TakenNames
Test-ValueIsArray $NamesToTest
@($TakenNames + $NamesToTest) | ForEach-Object { Test-ValueIsString $_ }
Return ($TakenNames.Where( { $NamesToTest -Contains $_ } ).Count -Eq 0)
}
Function Test-OsNotSupported {
$SupportedEditions = ("Education", "Enterprise", "Professional")
$CurrentEdition = (Get-WindowsEdition -Online).Edition
$EditionSupported = $SupportedEditions.Contains($CurrentEdition)
$Windows64Bit = [Environment]::Is64BitOperatingSystem
Return !($EditionSupported -And $Windows64Bit)
}
Function Test-PathAvailable($Path) {
Test-ValueIsPath $Path
Return !(Test-Path $Path)
}
Function Test-PSRunsNotAsAdmin {
$CurrentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$Principal = New-Object Security.Principal.WindowsPrincipal($CurrentUser)
$AdminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
Return !($Principal.IsInRole($AdminRole))
}
Function Test-RamNotEnough {
Return ((Get-TotalRamInstalled) -Lt 4GB)
}
Function Test-StorageNotEnough($DriveLetter) {
Test-ValueIsDriveLetter $DriveLetter
Return ((Get-AvailableStorage $DriveLetter) -Lt 15GB)
}
Function Test-SubnetAvailable($NetworkID) {
Test-ValueIsIPv4 $NetworkID
$HostAddresses = Get-NetIPAddress -AddressFamily "IPv4"
ForEach ($Address In $HostAddresses) {
$AddressSubnet = Get-Subnet $Address.IPAddress $Address.PrefixLength
$IPRange = Get-IPRangeInSubnet $AddressSubnet $Address.PrefixLength
If (Test-IPAddressInRange $NetworkID $IPRange.From $IPRange.To) {
Return $False
}
}
Return $True
}