Quantcast
Viewing all articles
Browse latest Browse all 21975

One parameter depends on another

I've got a PowerShell script that has the following syntax:

Get-Stardate [[-Time] <Object>] [-Decimals <Int32>] [-UTC] [<CommonParameters>]

The param declaration is:

param
(
    [Parameter(Position=0, ValueFromPipeline=$true)]
    $Time = (Get-Date),

    [int] $Decimals = 1,

    [switch] $UTC = $false
)

I'm trying to figure out how to disallow the use of the UTC switch if the -Time parameter hasn't been specified, but also to allow -Time to be set to the current time if it hasn't. That is, I want the syntax to look like this:

Get-Stardate [[-Time] <Object> [-UTC]] [-Decimals <Int32>] [<CommonParameters>]

The idea is that a user running the script without -Time wants the current time, with just -Time is specifying a LOCAL time, and with -Time and -UTC is specifying a UTC time.

Can this be done? Alternatively, is there a special way to indicate, in a string to be converted to [DateTime], that the string specifies UTC?


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>