Customizing Your Console

Standard

There are lots of posts out there about customizing the PS console, from colorization, fonts, eventing, and more.

As a daily PowerSheller, timestamping commands helps me keep track of when I performed a particular task. Thus, I added this to my PowerShell profile, located at C:\Users\myusername\Documents\WindowsPowershell\profile.ps1

 


Function prompt {"PS "+[DateTime]::Now.ToString("hh:mm:ss")+">"}

 

For further endeavors, here are some in-depth links on creating PS profiles and console customization:

 

PS Profiles:

https://blogs.technet.microsoft.com/heyscriptingguy/2012/05/21/understanding-the-six-powershell-profiles/

https://technet.microsoft.com/en-us/library/bb613488(v=vs.85).aspx

https://www.howtogeek.com/50236/customizing-your-powershell-profile/

https://www.simple-talk.com/sysadmin/powershell/persistent-powershell-the-powershell-profile/

 

Console Customization:

https://technet.microsoft.com/en-us/library/ff678294.aspx

https://blogs.technet.microsoft.com/undocumentedfeatures/2016/01/22/customizing-the-windows-powershell-console/

https://blogs.technet.microsoft.com/heyscriptingguy/2011/12/17/customize-the-powershell-console-for-increased-efficiency/

http://www.gngrninja.com/script-ninja/2016/3/20/powershell

Moving the Mouse

Standard

As a first post, I thought I would start with something fun – moving the mouse! To be noted – this is not the same as simulating user input. I’ll save that for a later post.

More features may get added later – timers, sound alert, maybe others. For now, here is a simple script that will either move the mouse from left to right, or top to bottom.

All comments welcome!

<#
.Synopsis
Moves the mouse cursor either from left-to-right
or top-to-bottom indefinitely.
.EXAMPLE
.\Move-Mouse_v1_0.ps1 -MotionType LeftToRight
.EXAMPLE
.\Move-Mouse_v1_0.ps1 -MotionType TopToBottom
.EXAMPLE
Press Ctrl+C to stop the script
#>

[CmdletBinding()]
Param
(
    [Parameter(Mandatory=$True,Position=1)]
    [ValidateNotNullOrEmpty()]
[ValidateSet("LeftToRight","TopToBottom")]
    [string[]]$MotionType = @("LeftToRight","TopToBottom")
)

BEGIN
{
    Function Load-Assemblies
    {
        [System.Reflection.Assembly]::LoadWithPartialName(‘System.Windows.Forms’) | Out-Null
    }

    Function Get-MonitorResolution
    {
        $script:screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
        $script:monitorHeight = $script:screen.Height
        $script:monitorWidth = $script:screen.Width
    }

    Function Move-Mouse
    {
        $script:startHeight = [int]$script:monitorHeight/2
        $script:startWidth = [int]$script:monitorWidth/2

        if($MotionType -eq "LeftToRight")
        {
            Move-LeftToRight
        }

        if($MotionType -eq "TopToBottom")
        {
            Move-TopToBottom
        }
    }

    Function Move-LeftToRight
    {
        $xPos = 0

        # Initial Cursor Position
        [System.Windows.Forms.Cursor]::Position = "$($xPos),$($script:startHeight)"

        # Keep moving right until at the edge of the screen
        do
        {
            $xPos++
            [System.Windows.Forms.Cursor]::Position ="$($xPos),$($script:startHeight)"
Start-Sleep -Milliseconds .5
        }
        until ($xPos -eq $script:monitorWidth)

        # Keep moving left until at the edge of the screen
        do
        {
            $xPos--
            [System.Windows.Forms.Cursor]::Position ="$($xPos),$($script:startHeight)"

            # Adjust to increase or decrease mouse speed
            Start-Sleep -Milliseconds .5
        }
        until ($xPos -eq 0)

        # Repeat indefinitely
        Move-LeftToRight
    }

    Function Move-TopToBottom
    {
        $yPos = 0

        # Initial Cursor Position
        [System.Windows.Forms.Cursor]::Position = "$($script:startWidth),$($yPos)"

        # Keep moving down until at the edge of the screen
        do
        {
            $yPos++
            [System.Windows.Forms.Cursor]::Position ="$($script:startWidth),$($yPos)"
            Start-Sleep -Milliseconds .5
        }
        until ($yPos -eq $script:monitorHeight)

        # Keep moving up until at the edge of the screen
        do
        {
            $yPos--
            [System.Windows.Forms.Cursor]::Position ="$($script:startWidth),$($yPos)"

            # Adjust to increase or decrease mouse speed
            Start-Sleep -Milliseconds .5
        }
        until ($yPos -eq 0)

        # Repeat indefinitely
        Move-TopToBottom
    }
}

PROCESS
{
    Load-Assemblies
    Get-MonitorResolution
    Move-Mouse
}

END
{

}