SOLVED

New-PSRoleCapabilityFile : The member 'FunctionDefinitions' must contain the required key 'Name'.

Copper Contributor
PS C:\> $params | FL *

Name  : Description
Key   : Description
Value : Role capabilities for Role1, including restricted DHCP scope management

Name  : VisibleAliases
Key   : VisibleAliases
Value : {where, ?, help, %...}

Name  : VisibleCmdlets
Key   : VisibleCmdlets
Value : {Where-Object, Foreach-Object, Exit-PSSession, Get-Command...}

Name  : GUID
Key   : GUID
Value : 12b3c45d-6e78-9012-3a45-67b89c0de1f2

Name  : Author
Key   : Author
Value : Powershell Administrator

Name  : VisibleFunctions
Key   : VisibleFunctions
Value : {Set-DhcpServerv4Scope, Add-DhcpServerv4Lease, Remove-DhcpServerv4Lease, Add-DhcpServerv4Reservation...}

Name  : Path
Key   : Path
Value : R:\DHCP_JEA\RoleCapabilities\Role1.psrc

Name  : FunctionDefinitions
Key   : FunctionDefinitions
Value : {FunctionOne, FunctionTwo}

PS C:\> $FunctionOne = @{
>>     Name = 'FunctionOne'
>>     ScriptBlock = { Write-Host "Executing Function One" }
>> }
PS C:\>
PS C:\> $FunctionTwo = @{
>>     Name = 'FunctionTwo'
>>     ScriptBlock = { param($Param1) Write-Host "Function Two received: $Param1" }
>> }
PS C:\>
PS C:\> $FunctionDefinitions = @{
>>     'FunctionOne' = $FunctionOne
>>     'FunctionTwo' = $FunctionTwo
>> }
PS C:\>
PS C:\> $params['FunctionDefinitions'] = $FunctionDefinitions
PS C:\> New-PSRoleCapabilityFile @params
New-PSRoleCapabilityFile : The member 'FunctionDefinitions' must contain the required key 'Name'. Add the require
key to the file R:\DHCP_JEA\RoleCapabilities\Role1.psrc.
At line:1 char:1
+ New-PSRoleCapabilityFile @params
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-PSRoleCapabilityFile], CmdletInvocationException
    + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.NewPSRoleCapabilityFileCommand

I'm having a hell of a time trying to specify multiple functions to the FunctionDefinition parameter of New-PSRoleCapabilityFile. I have legitimately exhausted ChatGPT and it suggested that I should perhaps ask some humans.

Does anyone have any ideas? This is for a not-so-simple JEA configuration that ultimtely hopes to provide Role based Administration for DHCP.

1 Reply
best response confirmed by cmcknz77 (Copper Contributor)
Solution

@cmcknz77 

 

Looking at the documentation, it appears the -FunctionDefinitions parameter requires an array of HashTable elements, where on lines 45 to 48, you're providing a HashTable that in turn contains two more HashTables.

 

 

Try this instead (in lieu of your current lines 45 to 48):

 

$FunctionDefinitions = @(
    $FunctionOne
    , $FunctionTwo
)

 

Cheers,

Lain

1 best response

Accepted Solutions
best response confirmed by cmcknz77 (Copper Contributor)
Solution

@cmcknz77 

 

Looking at the documentation, it appears the -FunctionDefinitions parameter requires an array of HashTable elements, where on lines 45 to 48, you're providing a HashTable that in turn contains two more HashTables.

 

 

Try this instead (in lieu of your current lines 45 to 48):

 

$FunctionDefinitions = @(
    $FunctionOne
    , $FunctionTwo
)

 

Cheers,

Lain

View solution in original post