Author Posts

November 22, 2017 at 11:49 am

Hi,

I'm trying to assign a permission set to a user in NAV. Similar to assigning a group in AD.
I'm dong the following:

$SourceUser = 'domain\user1'
$DestinationUser = 'domain\user2'
$SourceGroups = Get-NAVServerUserPermissionSet -ServerInstance "Server" -WindowsAccount $SourceUser |  select PermissionSetID
$SourceGroupsresult  = $SourceGroups | Out-String
New-NavServerUserPermissionSet -ServerInstance "Server" -WindowsAccount $DestinationUser -PermissionSetId $SourceGroupsresult

I get the following error:

New-NavServerUserPermissionSet : The length of the string is 205, but it must be less than or equal to 20 characters. Value: PermissionSetID     
---------------     
Perm_set1              
Perm_set2
Perm_set3  
Perm_set4               
Pe...
At line:1 char:1
+ New-NavServerUserPermissionSet -ServerInstance "Server" -Windows ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (0:Int32) [New-NAVServerUserPermissionSet], FaultException`1
    + FullyQualifiedErrorId : MicrosoftDynamicsNavServer$Server,Microsoft.Dynamics.Nav.Management.Cmdlets.NewNavServerUserPermissionSet

Can anyone help?

November 22, 2017 at 12:48 pm

I'd check the contents of $SourceGroupsresult.
I suspect you have multiple ids in there rather than the 1 that's expected

November 22, 2017 at 12:57 pm

hi Richard,

Yep, there's about 6 or 7 results in the out string for the permissionsetID.
How would I then get around this that I can use the 6 or 7 results?

Thanks

November 22, 2017 at 1:07 pm

could you not use something like below ?

foreach ($result in $SourceGroupsresult)

{
New-NavServerUserPermissionSet -ServerInstance "Server" -WindowsAccount $DestinationUser -PermissionSetId $result
}

November 22, 2017 at 2:09 pm

hi Simon,

Running as you suggested, I get the error message as before.
When I change it a little to run it on the variable result:

foreach ($result in $SourceGroups)
{
New-NavServerUserPermissionSet -ServerInstance "Server" -WindowsAccount $DestinationUser -PermissionSetId $result
}

I get the following:
New-NavServerUserPermissionSet : The length of the string is 24, but it must be less than or equal to 20 characters. Value: @{PermissionSetID=SetPe}

This error message continues for every permission set. So I end up with 8 error messages in total.

Thanks

November 22, 2017 at 2:36 pm

I would see what is in $result and see if I needed to trim any data out of it.

November 22, 2017 at 3:44 pm

It looks like I'd have to trim this part @{PermissionSetID= and at the end this bracket: }
Something like this then?
$result = $result.TrimStart(@{ }, "PermissionSetID=")

November 22, 2017 at 5:02 pm

You could try

$SourceGroups = Get-NAVServerUserPermissionSet -ServerInstance "Server" -WindowsAccount $SourceUser |  
select -first 1 |
select -expandproperty PermissionSetID