I have 2 pieces of code:
# code 1:
[type]$t1 = [switch]
# all is ok, code works as expected
#code 2:
function test ([type]$t2) { }
test -t2 [switch]
# here we get error. can't convert from string to system.type
I know, I can write: test -t2 "System.Management.Automation.SwitchParameter", but it’s ugly!!
Why can i set [switch] to [type]variable, but can’t pass it to function??
You can do this:
Or you can use the example from code1 and pass in the
$t1itself: