|
| 1 | +--- |
| 2 | +external help file: PSScriptTools-help.xml |
| 3 | +Module Name: PSScriptTools |
| 4 | +online version: |
| 5 | +schema: 2.0.0 |
| 6 | +--- |
| 7 | + |
| 8 | +# New-FunctionItem |
| 9 | + |
| 10 | +## SYNOPSIS |
| 11 | + |
| 12 | +Create a function item from the console |
| 13 | + |
| 14 | +## SYNTAX |
| 15 | + |
| 16 | +```powershell |
| 17 | +New-FunctionItem [-Name] <String> [-Scriptblock] <ScriptBlock> |
| 18 | +[[-Description] <String>] [-Passthru] [-WhatIf] [-Confirm] |
| 19 | +[<CommonParameters>] |
| 20 | +``` |
| 21 | + |
| 22 | +## DESCRIPTION |
| 23 | + |
| 24 | +You can use this function to create a quick function definition directly from the console. This command does not write anything to the pipeline unless you use -Passthru. |
| 25 | + |
| 26 | +## EXAMPLES |
| 27 | + |
| 28 | +### EXAMPLE 1 |
| 29 | + |
| 30 | +```powershell |
| 31 | +PS C:\> New-FunctionItem -name ToTitle -scriptblock {param([string]$Text) |
| 32 | +(Get-Culture).TextInfo.ToTitleCase($text.toLower())} -passthru |
| 33 | +
|
| 34 | +CommandType Name Version Source |
| 35 | +----------- ---- ------- ------ |
| 36 | +Function ToTitle |
| 37 | +``` |
| 38 | + |
| 39 | +### EXAMPLE 2 |
| 40 | + |
| 41 | +```powershell |
| 42 | +PS C:\> {Get-Date -format g | Set-Clipboard} | New-FunctionItem -name Copy-Date |
| 43 | +``` |
| 44 | + |
| 45 | +## PARAMETERS |
| 46 | + |
| 47 | +### -Name |
| 48 | + |
| 49 | +What is the name of your function? |
| 50 | + |
| 51 | +```yaml |
| 52 | +Type: String |
| 53 | +Parameter Sets: (All) |
| 54 | +Aliases: |
| 55 | + |
| 56 | +Required: True |
| 57 | +Position: 1 |
| 58 | +Default value: None |
| 59 | +Accept pipeline input: False |
| 60 | +Accept wildcard characters: False |
| 61 | +``` |
| 62 | +
|
| 63 | +### -Scriptblock |
| 64 | +
|
| 65 | +What is your function's scriptblock? |
| 66 | +
|
| 67 | +```yaml |
| 68 | +Type: ScriptBlock |
| 69 | +Parameter Sets: (All) |
| 70 | +Aliases: |
| 71 | + |
| 72 | +Required: True |
| 73 | +Position: 2 |
| 74 | +Default value: None |
| 75 | +Accept pipeline input: True (ByValue) |
| 76 | +Accept wildcard characters: False |
| 77 | +``` |
| 78 | +
|
| 79 | +### -Description |
| 80 | +
|
| 81 | +You can specify an optional description. This only lasts for as long as your function is loaded. |
| 82 | +
|
| 83 | +```yaml |
| 84 | +Type: String |
| 85 | +Parameter Sets: (All) |
| 86 | +Aliases: |
| 87 | + |
| 88 | +Required: False |
| 89 | +Position: 3 |
| 90 | +Default value: None |
| 91 | +Accept pipeline input: False |
| 92 | +Accept wildcard characters: False |
| 93 | +``` |
| 94 | +
|
| 95 | +### -Passthru |
| 96 | +
|
| 97 | +Show the newly created function. |
| 98 | +
|
| 99 | +```yaml |
| 100 | +Type: SwitchParameter |
| 101 | +Parameter Sets: (All) |
| 102 | +Aliases: |
| 103 | + |
| 104 | +Required: False |
| 105 | +Position: Named |
| 106 | +Default value: False |
| 107 | +Accept pipeline input: False |
| 108 | +Accept wildcard characters: False |
| 109 | +``` |
| 110 | +
|
| 111 | +### -WhatIf |
| 112 | +
|
| 113 | +Shows what would happen if the cmdlet runs. The cmdlet is not run. |
| 114 | +
|
| 115 | +```yaml |
| 116 | +Type: SwitchParameter |
| 117 | +Parameter Sets: (All) |
| 118 | +Aliases: wi |
| 119 | + |
| 120 | +Required: False |
| 121 | +Position: Named |
| 122 | +Default value: None |
| 123 | +Accept pipeline input: False |
| 124 | +Accept wildcard characters: False |
| 125 | +``` |
| 126 | +
|
| 127 | +### -Confirm |
| 128 | +
|
| 129 | +Prompts you for confirmation before running the cmdlet. |
| 130 | +
|
| 131 | +```yaml |
| 132 | +Type: SwitchParameter |
| 133 | +Parameter Sets: (All) |
| 134 | +Aliases: cf |
| 135 | + |
| 136 | +Required: False |
| 137 | +Position: Named |
| 138 | +Default value: None |
| 139 | +Accept pipeline input: False |
| 140 | +Accept wildcard characters: False |
| 141 | +``` |
| 142 | +
|
| 143 | +### CommonParameters |
| 144 | +
|
| 145 | +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). |
| 146 | +
|
| 147 | +## INPUTS |
| 148 | +
|
| 149 | +### Scriptbloclk |
| 150 | +
|
| 151 | +## OUTPUTS |
| 152 | +
|
| 153 | +### None |
| 154 | +
|
| 155 | +### System.Management.Automation.FunctionInfo |
| 156 | +
|
| 157 | +## NOTES |
| 158 | +
|
| 159 | +Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ |
| 160 | +
|
| 161 | +## RELATED LINKS |
| 162 | +
|
| 163 | +[Show-FunctionItem](Show-FunctionItem.md) |
0 commit comments