< Back

New-MenuItem

Mon Jan 13, 2020 3:10 am

NAME New-MenuItem



SYNOPSIS

Create a new Menu-Item for a Menu.





SYNTAX

New-MenuItem [-Name <String>] [-DisplayName <String>] [-Description <String>] [-Action <ScriptBlock>]

[-DisableConfirm] [<CommonParameters>]



New-MenuItem [-Name <String>] [-DisplayName <String>] [-Description <String>] [-Action <ScriptBlock>]

[-DisableConfirm] [-MenuName <String>] [<CommonParameters>]



New-MenuItem [-Name <String>] [-DisplayName <String>] [-Description <String>] [-Action <ScriptBlock>]

[-DisableConfirm] [-MenuObject <PSObject>] [<CommonParameters>]





DESCRIPTION

Menu-Items are the action elements of the Menu. You add Menu-Items to a Menu.





PARAMETERS

-Name <String>



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-DisplayName <String>



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Description <String>



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Action <ScriptBlock>



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-DisableConfirm [<SwitchParameter>]



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-MenuName <String>



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-MenuObject <PSObject>



Required? false

Position? named

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

System.Management.Automation.PSObject





NOTES





NAME: New-MenuItem

AUTHOR: Tore Groneng tore@firstpoint.no @toregroneng tore.groneng@gmail.com

LASTEDIT: Aug 2016

KEYWORDS: General scripting Controller Menu



-------------------------- EXAMPLE 1 --------------------------



C:>New-MenuItem -Name "PasswordReset" -DisplayName "Reset a user password" -Action { Set-UserPassword }



This will create a new Menu-Item.

Since no MenuId is specified, it return the new object to the console. The switch parameter

DisableConfirm is not specified and the user will have to confirm the invokation after it

has been selected.









-------------------------- EXAMPLE 2 --------------------------



C:>$menu = Get-Menu -Name sub1



C:> $newMenuItem = @{

Name = "UnlockUser"

DisplayName = "Unlock a user"

Action = { Unlock-UserObject }

DisableConfirm = $true

}

C:> $menu | New-MenuItem @newMenuItem



This will create a new Menu-Item for the menu named sub1. The Menu-object is piped into the New-MenuItem cmdlet.

It will invoke a custom cmdlet Unlock-UserObject and it will not confirm with the user before invokation.









-------------------------- EXAMPLE 3 --------------------------



C:>$newMenuItem = @{



Name = "UnlockUser"

DisplayName = "Unlock a user"

Action = { Unlock-UserObject }

DisableConfirm = $true

}

C:> New-Menu -Name "sub1" -DisplayName "Sub-Menu for Skype" | New-MenuItem @newMenuItem



This will create a new Sub-Menu and add the UnlockUser Menu-Item to it using the pipeline.

It will invoke a custom cmdlet Unlock-UserObject and it will not confirm with the user before invokation.









-------------------------- EXAMPLE 4 --------------------------



C:>$newMenuItem = @{



Name = "UnlockUser"

DisplayName = "Unlock a user"

Action = { Show-Command -Name Unlock-UserObject }

DisableConfirm = $true

}

C:> New-Menu -Name "sub1" -DisplayName "Sub-Menu for Skype" | New-MenuItem @newMenuItem



This will create a new Sub-Menu and add the UnlockUser Menu-Item to it using the pipeline.

It will invoke the Show-Command cmdlet which will show a windows form with the parameters of the custom

cmdlet Unlock-UserObject. It will not confirm with the user before invokation. The user may cancel the

windows form without executing the cmdlet.









-------------------------- EXAMPLE 5 --------------------------



C:>$mainMenu = New-Menu -Name Main -DisplayName "Main Menu" -IsMainMenu



C:> $newMenuItem = @{

Name = "UnlockUser"

DisplayName = "Unlock a user"

Action = { Show-Command -Name Unlock-UserObject }

DisableConfirm = $true

}

C:> $item = New-MenuItem $newMenuItem

C:> $item | Add-MenuItem -Menu Main



This will create a new Sub-Menu and add the UnlockUser Menu-Item to it using the pipeline.











RELATED LINKS





CommonParameters : True

WorkflowCommonParameters : False

details : @{name=Set-MenuOption; noun=; verb=}

Syntax : @{syntaxItem=System.Object[]}

parameters : @{parameter=System.Object[]}

inputTypes : @{inputType=}

returnValues : @{returnValue=}

aliases : None



remarks : None

alertSet :

description :

examples :

Synopsis :

Set-MenuOption [[-MenuFillChar] <string>] [[-MenuFillColor] <ConsoleColor>] [[-Heading]

<string>] [[-HeadingColor] <ConsoleColor>] [[-SubHeading] <string>] [[-SubHeadingColor]

<ConsoleColor>] [[-FooterText] <string>] [[-FooterTextColor] <ConsoleColor>]

[[-MenuItemColor] <ConsoleColor>] [[-MenuNameColor] <ConsoleColor>] [[-MaxWith] <int>]

[<CommonParameters>]



ModuleName : CliMenu

nonTerminatingErrors :

xmlns:command : http://schemas.microsoft.com/maml/dev/command/2004/10

xmlns:dev : http://schemas.microsoft.com/maml/dev/2004/10

xmlns:maml : http://schemas.microsoft.com/maml/2004/10

Name : Set-MenuOption

Category : Function

Component :

Role :

Functionality :