-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShadow-Prelude2.ps1
114 lines (95 loc) · 3.22 KB
/
Shadow-Prelude2.ps1
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
class systeminfo {
##class properties
[string] $ComputerName
[string] $BIOSmanufacturer
[string] $BIOSVersion
[String] $Domain
[int] $NumberOfProcessors
[int] $NumberofCores
[double] $TotalPhysicalMemory
[string] $OperatingSystemName
[string] $OperatingSystemArchitecture
[string] $TimeZone
[double] $SizeOfCdrive
[double] $CdriveFreeSpace
## default constructor
SystemInfo(){}
## constructor with arguments
systemInfo([string]$ComputerName,[string]$Domain){
if(($ComputerName -eq '') -or ($ComputerName -eq $null)) {
throw [System.InvalidOperationException]::new(
"ComputerName is empty or null")
}
if(($Domain -eq '') -or ($Domain -eq $null)) {
throw [System.InvalidOperationException]::new(
"Domain is empty or null")
}
$this.ComputerName = $ComputerName
$this.Domain = $Domain
}
## Constructor to also populate properties
SystemInfo([string] $ComputerName){
if(($ComputerName -eq '') -or ($ComputerName -eq $null)) {
throw [System.InvalidOperationException]::new(
"ComputerName is empty or null")
}
if($ComputerName -ne $env:COMPUTERNAME) {
throw "$ComputerName NOT equl to loacl machine name"
}
$this.GetAllInfo()
}
[void] GetComputerInfo() {
$compsys = Get-CimInstance -ClassName win32_ComputerSystem
$this.ComputerName = $compsys.Name
$this.TotalPhysicalMemory = [math]::Ceiling($compsys.TotalPhysicalMemory / 1Gb)
$this.Domain = $compsys.Domain
$this.NumberOfProcessors = $compsys.NumberOfLogicalProcessors
}
[void] GetCoresInfo() {
$proc = Get-CimInstance -ClassName Win32_Processor
$this.NumberofCores = $proc.NumberOfCores
}
[void] GetBIOSINFO() {
$bios = Get-CimInstance -ClassName Win32_BIOS
$this.BIOSmanufacturer = $bios.Manufacturer
$this.BIOSVersion = $bios.Version
}
[void] GetOSINFO(){
$os = Get-CimInstance -ClassName Win32_OperatingSystem
$this.OperatingSystemName = $os.Caption
$this.OperatingSystemArchitecture = $os.OSArchitecture
}
[void] GetTimeZoneInfo(){
$this.TimeZone = (Get-TimeZone).DisplayName
}
[void] GetDiskInfo(){
$disk = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'"
$this.SizeOfCdrive = [math]::Round(($disk.Size / 1Gb), 2)
$this.CdriveFreeSpace = [math]::Round(($disk.FreeSpace /1Gb), 2)
}
[void] GetAllInfo () {
$this.GetComputerInfo()
$this.GetCoresInfo()
$this.GetBIOSINFO()
$this.GetOSINFO()
$this.GetTimeZoneInfo()
$this.GetDiskInfo()
}
[double] CalcFreeSpacePerc() {
if(($this.SizeOfCdrive -eq 0) -or ($this.CdriveFreeSpace -eq 0)){
$this.GetDiskInfo()
}
$perc = ($this.CdriveFreeSpace / $this.SizeOfCdrive) * 100
return [math]::round($perc, 1)
}
}
##
## create class instance
##
$sysinfo = [systemInfo]::new($env:COMPUTERNAME)
##
## run pester tests
## data derived by different method
## wherever possible though maybe
## the same under the hood
##