functions/Set-PSClock.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

Function Set-PSClock {
    [cmdletbinding(SupportsShouldProcess)]
    [OutputType("none")]
    Param(
        [Parameter(Position=0,HelpMessage = "Specify a font color like Green or an HTML code like '#FF1257EA'",ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [string]$Color,

        [Parameter(Position = 1, HelpMessage = "Specify a .NET format string value like F, or G.",ValueFromPipelineByPropertyName)]
        [alias("format")]
        [ValidateNotNullOrEmpty()]
        [string]$DateFormat,

        [Parameter(HelpMessage = "How large do you want the font size?",ValueFromPipelineByPropertyName)]
        [ValidateScript({ $_ -gt 8 })]
        [alias("size")]
        [int]$FontSize,

        [Parameter(HelpMessage = "Specify a font style.",ValueFromPipelineByPropertyName)]
        [ValidateSet("Normal", "Italic", "Oblique")]
        [alias("style")]
        [string]$FontStyle,

        [Parameter(HelpMessage = "Specify a font weight.",ValueFromPipelineByPropertyName)]
        [ValidateSet("Normal", "Bold", "Light")]
        [alias("weight")]
        [string]$FontWeight,

        [Parameter(HelpMessage = "Specify a font family.",ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [alias("family")]
        [string]$FontFamily,

        [Parameter(HelpMessage = "Should the clock be on top of other applications?",ValueFromPipelineByPropertyName)]
        [switch]$OnTop,

        [switch]$Passthru
    )

    Write-Verbose "Starting ($myinvocation.mycommand)"
    if ($IsLinux -OR $isMacOS) {
        Write-Warning "This command requires a Windows platform"
        return
    }

    $settings = "FontSize", "FontStyle", "FontWeight", "Color", "OnTop", "DateFormat", "FontFamily"
    if ($PSClockSettings -And $PSClockSettings.Running) {
        Foreach ($setting in $settings) {
            if ($PSBoundParameters.ContainsKey($setting)) {
                $value = $PSBoundParameters[$setting]
                $action = "Setting value to $value"
                Write-Verbose "Setting $setting to $value"
                if ($PSCmdlet.ShouldProcess($setting, $action)) {
                    $Global:PSClockSettings[$setting] = $Value
                }
            }
        } #foreach setting

        if ($Passthru) {
            Start-Sleep -Seconds 1
            Get-PSClock
        }
    } #if running clock found
    else {
        Write-Warning "Can't find a running clock. Do you need to start one?"
    }

    Write-Verbose "Ending ($myinvocation.mycommand)"
}