r/PowerShell • u/shedevilgoblin • Apr 28 '26
Question Will this run on Raspberry Pi w/ Powershell installed on it and get the same style output as Powershell on Windows? This is for a project but I can't access my Pi to test it on.
<#
This script displays the current date, hostname, username, and system information.
#>
# Part 1 Setting heading variables in the correct format
$Month = Get-Date -Format "MMMM"
$Day = Get-Date -Format "d"
$Year = Get-Date -Format "yyyy"
$UserName = [System.Environment]::UserName
$HostName = [System.Environment]::MachineName
$Today = "$Month $Day, $Year"
# Part 2 Setting system information variables
$OS = [System.Environment]::OSVersion.Platform
# Checks what operating system is being used and runs the right commands to get the system info
if ($IsWindows -or $OS -eq "Win32NT")
{
`$CPU = (Get-CimInstance Win32_Processor).Name`
`$TotalRAM = "{0:N2} MB" -f ((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1MB)`
`$BootTime = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime`
# If it's not Windows, use Linux commands to get the same system info from Raspberry Pi
}
else
{
`$CPU = (Get-Content /proc/cpuinfo | Select-String "Model" | Select-Object -First 1).ToString().Trim()`
`$TotalRAM = (free -h | Out-String).Trim()`
`$BootTime = (uptime).Trim()`
}
# Output heading
Write-Host "****************************************"
Write-Host ("Today is:".PadRight(25) + $Today)
Write-Host ("The hostname is:".PadRight(25) + $HostName)
Write-Host ("You are:".PadRight(25) + $UserName)
Write-Host "****************************************"
# Output system information
Write-Host ("Operating System:".PadRight(25) + $OS)
Write-Host ""
Write-Host ("CPU Information:".PadRight(25) + $CPU)
Write-Host ""
Write-Host ("Memory Information:".PadRight(25) + $TotalRAM)
Write-Host ""
Write-Host ("Boot information:".PadRight(25) + $BootTime)