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

This topic contains 7 replies, has 3 voices, and was last updated by  Richard Siddaway 2 weeks, 4 days ago.

  • Author
    Posts
  • #84760

    Noel
    Participant

    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?

  • #84763

    Richard Siddaway
    Moderator

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

    • #84766

      Noel
      Participant

      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

  • #84767

    Simon B
    Participant

    could you not use something like below ?

    foreach ($result in $SourceGroupsresult)

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

    • #84769

      Noel
      Participant

      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

  • #84776

    Simon B
    Participant

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

    • #84781

      Noel
      Participant

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

  • #84812

    Richard Siddaway
    Moderator

    You could try

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

You must be logged in to reply to this topic.