Lets say I have a simple script with one parameter, which has a default value:
param(
[string] $logOutput = "C:\SomeFolder\File.txt"
)
# Script...
And lets say a user runs the script like so:
PS C:\> .\MyScript.ps1 -logOutput "C:\SomeFolder\File.txt"
Is there any way the script is able to know that the user explicitly entered a value (which happens to be the same as the default), rather than let the default be decided automatically?
In this example, the script is going to print some output to the given file. If the file was not specified by the user (i.e. the default got used automatically), then the script will not produce an error in the event it is unable to write to that location, and will just carry on silently. However, if the user did specify the location, and the script is unable to write to that location, then it should produce an error and stop, warning the user. How could I implement this kind of logic?