Link to home
Start Free TrialLog in
Avatar of Kelly Garcia
Kelly GarciaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

[switch] $NoInheritance - Powershell Code

Hi All,

I am trying to understand this line of code, what exactly is the [switch] $NoInheritance ? how does it work?

function DoPermissions
{
    param( $permissionGroup, $folder, $level, [switch] $NoInheritance)
}

Open in new window


Thank you in advance
Avatar of Qlemo
Qlemo
Flag of Germany image

A switch is an optional parameter without (explicit) value (in fact it is a boolean). If left out when calling the function, it is $false, if you call with -NoInheritance it is $true.
You can call it with an explicit value, which you might want to do if the default value differs from $false, by e.g. using -NoInheritance:$false.
Avatar of Kelly Garcia

ASKER

ok I kind of get it, if do dopermissions --NoInheritance it will:

switch (noinheritance)
{
Pattern 1 {Statement block}
 Pattern 2 {Statement block}
 Pattern n {Statement block}
}

is this correct?
No. [switch] and switch are totally different kind of things. $NoInheritance just has the values $false or $true, depending on what has been provided or left out at calling the function.
ok thank you, any examples to help me understand?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial