Update write-motd.ps1

Added $Uptime, $CPU_info and $OS
This commit is contained in:
Alain Herve 2022-04-29 20:33:56 +02:00 committed by GitHub
parent 0c4d8c927d
commit a04f89554d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,103 +1,94 @@
<# <#
.SYNOPSIS .SYNOPSIS
Writes the message of the day (MOTD) Writes the message of the day
.DESCRIPTION .DESCRIPTION
This PowerShell script writes the message of the day (MOTD). This PowerShell script writes the message of the day (MOTD).
.EXAMPLE .EXAMPLE
PS> ./write-motd PS> ./write-motd
.NOTES .NOTES
Author: Markus Fleschutz / License: CC0 Author: Markus Fleschutz / License: CC0
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
#> #>
param ()
# Retrieve information: # Retrieve information:
$CurrentTime = Get-Date -format "yyyy-MM-dd HH:mm"
$TimeZone = (Get-TimeZone).id $TimeZone = (Get-TimeZone).id
$UserName = $(whoami) $UserName = [Environment]::USERNAME
$ComputerName = $(hostname) $ComputerName = [System.Net.Dns]::GetHostName().ToLower()
$OSName = $PSVersionTable.OS $OSName = "$((Get-WmiObject win32_operatingsystem).caption) Build: $([System.Environment]::OSVersion.Version.Build)"
$PowerShellVersion = $PSVersionTable.PSVersion $PowerShellVersion = $PSVersionTable.PSVersion
$PowerShellEdition = $PSVersionTable.PSEdition $PowerShellEdition = $PSVersionTable.PSEdition
$UptimeDays = (Get-Uptime).Days $dt = [datetime]::Now; $day = $dt.ToLongDateString().split(',')[1].trim()
$UptimeHours = (Get-Uptime).Hours if ($day.EndsWith('1')) { $day += 'st' }elseif ($day.EndsWith('2')) { $day += 'nd' }elseif ($day.EndsWith('3')) { $day += 'rd' }else { $day += 'th' }
$Uptime = "$UptimeDays days, $UptimeHours hours" $CurrentTime = "$day, $($dt.Year) $($dt.Hour):$($dt.Minute)"
$Uptime = 'S' + $(net statistics workstation | find "Statistics since").Substring(12).Trim();
$NumberOfProcesses = (Get-Process).Count $NumberOfProcesses = (Get-Process).Count
$CPU_Info = $env:PROCESSOR_IDENTIFIER + ' Rev: ' + $env:PROCESSOR_REVISION
#$Logical_Disk = Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object -Property DeviceID -eq $OS.SystemDrive # $Logical_Disk = Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object -Property DeviceID -eq $OS.SystemDrive
#$Processor = Get-CimInstance -ClassName Win32_Processor # $Processor = Get-CimInstance -ClassName Win32_Processor
#$Current_Load = $ReturnedValues.Processor.LoadPercentage $Current_Load = "{0}%" -f $(Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select-Object -ExpandProperty Average)
#$Memory_Size = "{0}mb/{1}mb Used" -f (([math]::round($ReturnedValues.Operating_System.TotalVisibleMemorySize/1KB))- # $Memory_Size = "{0}mb/{1}mb Used" -f (([math]::round($ReturnedValues.Operating_System.TotalVisibleMemorySize / 1KB)) - ([math]::round($ReturnedValues.Operating_System.FreePhysicalMemory / 1KB))), ([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 Used" -f (([math]::round($ReturnedValues.Logical_Disk.Size / 1GB) - [math]::round($ReturnedValues.Logical_Disk.FreeSpace / 1GB))), ([math]::round($ReturnedValues.Logical_Disk.Size / 1GB))
#$Disk_Size = "{0}gb/{1}gb Used" -f (([math]::round($ReturnedValues.Logical_Disk.Size/1GB)- # Print Results
#[math]::round($ReturnedValues.Logical_Disk.FreeSpace/1GB))),([math]::round($ReturnedValues.Logical_Disk.Size/1GB)) [Environment]::NewLine
Write-Host " ,.=:^!^!t3Z3z., " -ForegroundColor Red
# Write to the Console Write-Host " :tt:::tt333EE3 " -ForegroundColor Red
Write-Host " Et:::ztt33EEE " -ForegroundColor Red -NoNewline
write-host "" Write-Host " @Ee., .., " -ForegroundColor green -NoNewline
write-host "" Write-Host " Time: " -ForegroundColor Red -NoNewline
write-host " ,.=:^!^!t3Z3z., " -foregroundcolor Red Write-Host "$CurrentTime" -ForegroundColor Cyan
write-host " :tt:::tt333EE3 " -foregroundcolor Red Write-Host " ;tt:::tt333EE7" -ForegroundColor Red -NoNewline
Write-Host " ;EEEEEEttttt33# " -ForegroundColor Green -NoNewline
write-host " Et:::ztt33EEE " -foregroundcolor Red -nonewline Write-Host " Timezone: " -ForegroundColor Red -NoNewline
write-host " @Ee., .., " -foregroundcolor green -nonewline Write-Host "$TimeZone" -ForegroundColor Cyan
write-host " Time: " -foregroundcolor Red -nonewline Write-Host " :Et:::zt333EEQ." -NoNewline -ForegroundColor Red
write-host "$CurrentTime" -foregroundcolor Cyan Write-Host " SEEEEEttttt33QL " -NoNewline -ForegroundColor Green
Write-Host " User: " -NoNewline -ForegroundColor Red
write-host " ;tt:::tt333EE7" -foregroundcolor Red -nonewline Write-Host "$UserName" -ForegroundColor Cyan
write-host " ;EEEEEEttttt33# " -foregroundcolor Green -nonewline Write-Host " it::::tt333EEF" -NoNewline -ForegroundColor Red
write-host " Timezone: " -foregroundcolor Red -nonewline Write-Host " @EEEEEEttttt33F " -NoNewline -ForegroundColor Green
write-host "$TimeZone" -foregroundcolor Cyan Write-Host " Hostname: " -NoNewline -ForegroundColor Red
Write-Host "$ComputerName" -ForegroundColor Cyan
write-host " :Et:::zt333EEQ." -NoNewline -foregroundcolor Red Write-Host " ;3=*^``````'*4EEV" -NoNewline -ForegroundColor Red
write-host " SEEEEEttttt33QL " -NoNewline -foregroundcolor Green Write-Host " :EEEEEEttttt33@. " -NoNewline -ForegroundColor Green
write-host " User: " -NoNewline -foregroundcolor Red Write-Host " OS: " -NoNewline -ForegroundColor Red
write-host "$UserName" -foregroundcolor Cyan Write-Host "$OSName" -ForegroundColor Cyan
write-host " it::::tt333EEF" -NoNewline -foregroundcolor Red Write-Host " ,.=::::it=., " -NoNewline -ForegroundColor Cyan
write-host " @EEEEEEttttt33F " -NoNewline -ForeGroundColor Green Write-Host "``" -NoNewline -ForegroundColor Red
write-host " Hostname: " -NoNewline -foregroundcolor Red Write-Host " @EEEEEEtttz33QF " -NoNewline -ForegroundColor Green
write-host "$ComputerName" -foregroundcolor Cyan Write-Host " Kernel: " -NoNewline -ForegroundColor Red
write-host " ;3=*^``````'*4EEV" -NoNewline -foregroundcolor Red Write-Host "NT " -NoNewline -ForegroundColor Cyan
write-host " :EEEEEEttttt33@. " -NoNewline -foregroundcolor Green Write-Host "$Kernel_Info" -ForegroundColor Cyan
write-host " OS: " -NoNewline -foregroundcolor Red Write-Host " ;::::::::zt33) " -NoNewline -ForegroundColor Cyan
write-host "$OSName" -foregroundcolor Cyan Write-Host " '4EEEtttji3P* " -NoNewline -ForegroundColor Green
write-host " ,.=::::it=., " -NoNewline -foregroundcolor Cyan Write-Host " Uptime: " -NoNewline -ForegroundColor Red
write-host "``" -NoNewline -foregroundcolor Red Write-Host "$Uptime" -ForegroundColor Cyan
write-host " @EEEEEEtttz33QF " -NoNewline -foregroundcolor Green Write-Host " :t::::::::tt33." -NoNewline -ForegroundColor Cyan
write-host " Kernel: " -NoNewline -foregroundcolor Red Write-Host ":Z3z.. " -NoNewline -ForegroundColor Yellow
write-host "NT " -NoNewline -foregroundcolor Cyan Write-Host " ````" -NoNewline -ForegroundColor Green
write-host "$Kernel_Info" -foregroundcolor Cyan Write-Host " ,..g. " -NoNewline -ForegroundColor Yellow
write-host " ;::::::::zt33) " -NoNewline -foregroundcolor Cyan Write-Host " PowerShell: " -NoNewline -ForegroundColor Red
write-host " '4EEEtttji3P* " -NoNewline -foregroundcolor Green Write-Host "$PowerShellVersion $PowerShellEdition" -ForegroundColor Cyan
write-host " Uptime: " -NoNewline -foregroundcolor Red Write-Host " i::::::::zt33F" -NoNewline -ForegroundColor Cyan
write-host "$Uptime" -foregroundcolor Cyan Write-Host " AEEEtttt::::ztF " -NoNewline -ForegroundColor Yellow
write-host " :t::::::::tt33." -NoNewline -foregroundcolor Cyan Write-Host " CPU: " -NoNewline -ForegroundColor Red
write-host ":Z3z.. " -NoNewline -foregroundcolor Yellow Write-Host "$CPU_Info" -ForegroundColor Cyan
write-host " ````" -NoNewline -foregroundcolor Green Write-Host " ;:::::::::t33V" -NoNewline -ForegroundColor Cyan
write-host " ,..g. " -NoNewline -foregroundcolor Yellow Write-Host " ;EEEttttt::::t3 " -NoNewline -ForegroundColor Yellow
write-host " PowerShell: " -NoNewline -foregroundcolor Red Write-Host " Processes: " -NoNewline -ForegroundColor Red
write-host "$PowerShellVersion $PowerShellEdition" -foregroundcolor Cyan Write-Host "$NumberOfProcesses" -ForegroundColor Cyan
write-host " i::::::::zt33F" -NoNewline -foregroundcolor Cyan Write-Host " E::::::::zt33L" -NoNewline -ForegroundColor Cyan
write-host " AEEEtttt::::ztF " -NoNewline -foregroundcolor Yellow Write-Host " @EEEtttt::::z3F " -NoNewline -ForegroundColor Yellow
write-host " CPU: " -NoNewline -foregroundcolor Red Write-Host " Current Load: " -NoNewline -ForegroundColor Red
write-host "$CPU_Info" -foregroundcolor Cyan Write-Host "$Current_Load" -ForegroundColor Cyan
write-host " ;:::::::::t33V" -NoNewline -foregroundcolor Cyan Write-Host " {3=*^``````'*4E3)" -NoNewline -ForegroundColor Cyan
write-host " ;EEEttttt::::t3 " -NoNewline -foregroundcolor Yellow Write-Host " ;EEEtttt:::::tZ`` " -NoNewline -ForegroundColor Yellow
write-host " Processes: " -NoNewline -foregroundcolor Red Write-Host " Memory: " -NoNewline -ForegroundColor Red
write-host "$NumberOfProcesses" -foregroundcolor Cyan Write-Host "$Memory_Size" -ForegroundColor Cyan
write-host " E::::::::zt33L" -NoNewline -foregroundcolor Cyan Write-Host " ``" -NoNewline -ForegroundColor Cyan
write-host " @EEEtttt::::z3F " -NoNewline -foregroundcolor Yellow Write-Host " :EEEEtttt::::z7 " -NoNewline -ForegroundColor Yellow
write-host " Current Load: " -NoNewline -foregroundcolor Red Write-Host " System Volume: " -NoNewline -ForegroundColor Red
write-host "$Current_Load" -foregroundcolor Cyan Write-Host "$Disk_Size" -ForegroundColor Cyan
#write-host "%" -foregroundcolor Cyan Write-Host " 'VEzjt:;;z>*`` " -ForegroundColor Yellow
write-host " {3=*^``````'*4E3)" -NoNewline -foregroundcolor Cyan [Environment]::NewLine
write-host " ;EEEtttt:::::tZ`` " -NoNewline -foregroundcolor Yellow
write-host " Memory: " -NoNewline -foregroundcolor Red
write-host "$Memory_Size" -foregroundcolor Cyan
write-host " ``" -NoNewline -foregroundcolor Cyan
write-host " :EEEEtttt::::z7 " -NoNewline -foregroundcolor Yellow
write-host " System Volume: " -NoNewline -foregroundcolor Red
write-host "$Disk_Size" -foregroundcolor Cyan
write-host " 'VEzjt:;;z>*`` " -foregroundcolor Yellow
write-host ""
exit 0 # success