Avatar of Kelly Garcia
Kelly Garcia
Flag 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
PowershellScripting Languages

Avatar of undefined
Last Comment
Qlemo

8/22/2022 - Mon
Qlemo

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.
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?
Qlemo

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Kelly Garcia

ASKER
ok thank you, any examples to help me understand?
ASKER CERTIFIED SOLUTION
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question