-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGet-MOTD.ps1
188 lines (172 loc) · 9.73 KB
/
Get-MOTD.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
Function Get-MOTD {
<#
.NAME
Get-MOTD
.SYNOPSIS
Displays system information to a host.
.DESCRIPTION
The Get-MOTD cmdlet is a system information tool written in PowerShell.
.EXAMPLE
#>
[CmdletBinding()]
Param(
[Parameter(Position=0,Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string[]]$ComputerName
,
[Parameter(Position=1,Mandatory=$false)]
[PSCredential]
[System.Management.Automation.CredentialAttribute()]$Credential
)
Begin {
If (-Not $ComputerName) {
$RemoteSession = $null
}
#Define ScriptBlock for data collection
$ScriptBlock = {
$Operating_System = Get-CimInstance -ClassName Win32_OperatingSystem
$Logical_Disk = Get-CimInstance -ClassName Win32_LogicalDisk |
Where-Object -Property DeviceID -eq $Operating_System.SystemDrive
Try {
$PCLi = Get-PowerCLIVersion
$PCLiVer = ' | PowerCLi ' + [string]$PCLi.Major + '.' + [string]$PCLi.Minor + '.' + [string]$PCLi.Revision + '.' + [string]$PCLi.Build
} Catch {$PCLiVer = ''}
If ($DomainName = ([System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()).DomainName) {$DomainName = '.' + $DomainName}
[pscustomobject]@{
Operating_System = $Operating_System
Processor = Get-CimInstance -ClassName Win32_Processor
Process_Count = (Get-Process).Count
Shell_Info = ("{0}.{1}" -f $PSVersionTable.PSVersion.Major,$PSVersionTable.PSVersion.Minor) + $PCLiVer
Logical_Disk = $Logical_Disk
}
}
} #End Begin
Process {
If ($ComputerName) {
If ("$ComputerName" -ne "$env:ComputerName") {
# Build Hash to be used for passing parameters to
# New-PSSession commandlet
$PSSessionParams = @{
ComputerName = $ComputerName
ErrorAction = 'Stop'
}
# Add optional parameters to hash
If ($Credential) {
$PSSessionParams.Add('Credential', $Credential)
}
# Create remote powershell session
Try {
$RemoteSession = New-PSSession @PSSessionParams
}
Catch {
Throw $_.Exception.Message
}
} Else {
$RemoteSession = $null
}
}
# Build Hash to be used for passing parameters to
# Invoke-Command commandlet
$CommandParams = @{
ScriptBlock = $ScriptBlock
ErrorAction = 'Stop'
}
# Add optional parameters to hash
If ($RemoteSession) {
$CommandParams.Add('Session', $RemoteSession)
}
# Run ScriptBlock
Try {
$ReturnedValues = Invoke-Command @CommandParams
}
Catch {
If ($RemoteSession) {
Remove-PSSession $RemoteSession
}
Throw $_.Exception.Message
}
# Assign variables
$Date = Get-Date
$OS_Name = $ReturnedValues.Operating_System.Caption + ' [Installed: ' + ([datetime]$ReturnedValues.Operating_System.InstallDate).ToString('dd-MMM-yyyy') + ']'
$Computer_Name = $ReturnedValues.Operating_System.CSName
If ($DomainName) {$Computer_Name = $Computer_Name + $DomainName.ToUpper()}
$Kernel_Info = $ReturnedValues.Operating_System.Version + ' [' + $ReturnedValues.Operating_System.OSArchitecture + ']'
$Process_Count = $ReturnedValues.Process_Count
$Uptime = "$(($Uptime = $Date - $($ReturnedValues.Operating_System.LastBootUpTime)).Days) days, $($Uptime.Hours) hours, $($Uptime.Minutes) minutes"
$Shell_Info = $ReturnedValues.Shell_Info
$CPU_Info = $ReturnedValues.Processor.Name -replace '\(C\)', '' -replace '\(R\)', '' -replace '\(TM\)', '' -replace 'CPU', '' -replace '\s+', ' '
$Current_Load = $ReturnedValues.Processor.LoadPercentage
$Memory_Size = "{0} MB/{1} MB " -f (([math]::round($ReturnedValues.Operating_System.TotalVisibleMemorySize/1KB))-
([math]::round($ReturnedValues.Operating_System.FreePhysicalMemory/1KB))),([math]::round($ReturnedValues.Operating_System.TotalVisibleMemorySize/1KB))
$Disk_Size = "{0} GB/{1} GB" -f (([math]::round($ReturnedValues.Logical_Disk.Size/1GB)-
[math]::round($ReturnedValues.Logical_Disk.FreeSpace/1GB))),([math]::round($ReturnedValues.Logical_Disk.Size/1GB))
# Write to the Console
Write-Host -Object ("")
Write-Host -Object ("")
Write-Host -Object (" ,.=:^!^!t3Z3z., ") -ForegroundColor Red
Write-Host -Object (" :tt:::tt333EE3 ") -ForegroundColor Red
Write-Host -Object (" Et:::ztt33EEE ") -NoNewline -ForegroundColor Red
Write-Host -Object (" @Ee., .., $($Date.ToString('dd-MMM-yyyy HH:mm:ss'))") -ForegroundColor Green
Write-Host -Object (" ;tt:::tt333EE7") -NoNewline -ForegroundColor Red
Write-Host -Object (" ;EEEEEEttttt33# ") -ForegroundColor Green
Write-Host -Object (" :Et:::zt333EEQ.") -NoNewline -ForegroundColor Red
Write-Host -Object (" SEEEEEttttt33QL ") -NoNewline -ForegroundColor Green
Write-Host -Object ("User: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("$env:USERDOMAIN\$env:UserName") -ForegroundColor Cyan
Write-Host -Object (" it::::tt333EEF") -NoNewline -ForegroundColor Red
Write-Host -Object (" @EEEEEEttttt33F ") -NoNewline -ForeGroundColor Green
Write-Host -Object ("Hostname: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("$Computer_Name") -ForegroundColor Cyan
Write-Host -Object (" ;3=*^``````'*4EEV") -NoNewline -ForegroundColor Red
Write-Host -Object (" :EEEEEEttttt33@. ") -NoNewline -ForegroundColor Green
Write-Host -Object ("OS: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("$OS_Name") -ForegroundColor Cyan
Write-Host -Object (" ,.=::::it=., ") -NoNewline -ForegroundColor Cyan
Write-Host -Object ("``") -NoNewline -ForegroundColor Red
Write-Host -Object (" @EEEEEEtttz33QF ") -NoNewline -ForegroundColor Green
Write-Host -Object ("Kernel: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("NT ") -NoNewline -ForegroundColor Cyan
Write-Host -Object ("$Kernel_Info") -ForegroundColor Cyan
Write-Host -Object (" ;::::::::zt33) ") -NoNewline -ForegroundColor Cyan
Write-Host -Object (" '4EEEtttji3P* ") -NoNewline -ForegroundColor Green
Write-Host -Object ("Uptime: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("$Uptime") -ForegroundColor Cyan
Write-Host -Object (" :t::::::::tt33.") -NoNewline -ForegroundColor Cyan
Write-Host -Object (":Z3z.. ") -NoNewline -ForegroundColor Yellow
Write-Host -Object (" ````") -NoNewline -ForegroundColor Green
Write-Host -Object (" ,..g. ") -NoNewline -ForegroundColor Yellow
Write-Host -Object ("Shell: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("PowerShell $Shell_Info") -ForegroundColor Cyan
Write-Host -Object (" i::::::::zt33F") -NoNewline -ForegroundColor Cyan
Write-Host -Object (" AEEEtttt::::ztF ") -NoNewline -ForegroundColor Yellow
Write-Host -Object ("CPU: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("$CPU_Info") -ForegroundColor Cyan
Write-Host -Object (" ;:::::::::t33V") -NoNewline -ForegroundColor Cyan
Write-Host -Object (" ;EEEttttt::::t3 ") -NoNewline -ForegroundColor Yellow
Write-Host -Object ("Processes: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("$Process_Count") -ForegroundColor Cyan
Write-Host -Object (" E::::::::zt33L") -NoNewline -ForegroundColor Cyan
Write-Host -Object (" @EEEtttt::::z3F ") -NoNewline -ForegroundColor Yellow
Write-Host -Object ("Current Load: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("$Current_Load") -NoNewline -ForegroundColor Cyan
Write-Host -Object ("%") -ForegroundColor Cyan
Write-Host -Object (" {3=*^``````'*4E3)") -NoNewline -ForegroundColor Cyan
Write-Host -Object (" ;EEEtttt:::::tZ`` ") -NoNewline -ForegroundColor Yellow
Write-Host -Object ("Memory: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("$Memory_Size`t") -ForegroundColor Cyan -NoNewline
New-PercentageBar -DrawBar -Value (([math]::round($ReturnedValues.Operating_System.TotalVisibleMemorySize/1KB))-([math]::round($ReturnedValues.Operating_System.FreePhysicalMemory/1KB))) -MaxValue ([math]::round($ReturnedValues.Operating_System.TotalVisibleMemorySize/1KB)); "`r"
Write-Host -Object (" ``") -NoNewline -ForegroundColor Cyan
Write-Host -Object (" :EEEEtttt::::z7 ") -NoNewline -ForegroundColor Yellow
Write-Host -Object ("System Volume: ") -NoNewline -ForegroundColor Red
Write-Host -Object ("$Disk_Size`t") -ForegroundColor Cyan -NoNewline
New-PercentageBar -DrawBar -Value (([math]::round($ReturnedValues.Logical_Disk.Size/1GB)-[math]::round($ReturnedValues.Logical_Disk.FreeSpace/1GB))) -MaxValue ([math]::round($ReturnedValues.Logical_Disk.Size/1GB)); "`r"
Write-Host -Object (" 'VEzjt:;;z>*`` ") -ForegroundColor Yellow
Write-Host -Object (" ```` ") -ForegroundColor Yellow
Write-Host -Object ("")
} #End Process
End {
If ($RemoteSession) {
Remove-PSSession $RemoteSession
}
}
} #End Function Get-MOTD