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

Welcome Forums General PowerShell Q&A 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

 
Participant
1 year, 4 months ago.

  • Author
    Posts
  • #84760

    Participant
    Points: 12
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

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

    • #84766

      Participant
      Points: 12
      Rank: Member

      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

    Participant
    Points: 69
    Rank: Member

    could you not use something like below ?

    foreach ($result in $SourceGroupsresult)

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

    • #84769

      Participant
      Points: 12
      Rank: Member

      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

    Participant
    Points: 69
    Rank: Member

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

    • #84781

      Participant
      Points: 12
      Rank: Member

      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

    Participant
    Points: 0
    Rank: Member

    You could try

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

The topic ‘The length of the string is 205, but it must be less than or equal to 20 charact’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort