The length of the string is 205, but it must be less than or equal to 20 charact

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?

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

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

could you not use something like below ?

foreach ($result in $SourceGroupsresult)

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

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

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

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=”)

You could try

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