# Copyright (c) Microsoft Corporation. All rights reserved. # # THIS SAMPLE CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, # WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. # IF THIS CODE AND INFORMATION IS MODIFIED, THE ENTIRE RISK OF USE OR RESULTS IN # CONNECTION WITH THE USE OF THIS CODE AND INFORMATION REMAINS WITH THE USER. function help { get-help $args[0] | out-host -paging } function man { get-help $args[0] | out-host -paging } function mkdir { new-item -type directory -path $args } function md { new-item -type directory -path $args } function prompt { [wmi]$Global:Cdrive=Get-WmiObject -query "Select * from win32_logicaldisk where deviceid='c:'" #Define Cdrive as global variable, which is type cast as a wmi $processcount=(Get-Process).Count #Define variable processcount as number of processes running $cpuload=(Get-WmiObject win32_processor).loadpercentage #cpuload is defined as a variable $diskinfoC=" Free C: "+"{0:N2}" -f (($global:Cdrive.freespace/1gb)/($global:cdrive.size/1gb)*100)+"%" #diskinfoC is defined, {0:N2} is .NET for 2 decimal places, -f is a the "format" property of the string object. # Then the amount of free space on drive C is divided by the size of drive C multiplies by 100 to get #the percentage of free space. $time=Get-WmiObject -class Win32_OperatingSystem #Define $time is object Win32_OperatingSystem $t=$time.ConvertToDateTime($time.Lastbootuptime) #Define #t as the result of the convertion of LastBootuptime into a readable dateTime format. [TimeSpan]$uptime=New-TimeSpan $t $(get-date) #Typecast the variable $uptime as a [timespan], the timespan cmdlet in powershell is a way to do date arithmetic in ps #This way we can compare our variable $t (Which was Lastbootuptime) and the current time Get-date cmdlet $up="$($uptime.days)d $($uptime.hours)h $($uptime.minutes)m $($uptime.seconds)s" #define variable $up to display the uptime in days/hours/minuted/seconds $TextToDisplay="CPU:"+$cpuload+"% Processes:" + $processcount + $diskinfoC+ " " + $diskinfoG+ " "+ ([char]0x25b2)+$up +" "+` (Get-Date -format g) #define one variable that contains all the data we collected so far. Write-Host -fore red $TextToDisplay #Write the information to the screen in red Write-Host "My PoSh:" $(get-location) -nonewline #Display the regular prompt. } & { for ($i = 0; $i -lt 26; $i++) { $funcname = ([System.Char]($i+65)) + ':' $str = "function global:$funcname { set-location $funcname } " invoke-expression $str } }