convert comma separated value to number RRS feed

  • Question

  • Hi 

    I'm trying to send data trough a webcall API and have to send a specific value as number.

    						$groupmembers = Get-ADGroupMember -Identity $group.SamAccountName -Recursive
    						$members = ""
    						foreach ($member in $groupmembers) {
    							$currentFlexAssets = (Get-ITGlueFlexibleAssets -filter_flexible_asset_type_id $Users_flex_asset_id -filter_organization_id $api__org_id -filter_name $member.name)
    							$value = $currentFlexAssets.data.attributes.'resource-url'
    							$Split = $value.split("{/}")
    							$members += $Split[7] + ", "
    						$members = $members.TrimEnd(", ")
    						$members2 = 1715837278175409, 1715837265510575, 1715837270687920

    members is the tag field build up from the string split and comma separted.

    members2 is the tag field which I've typed myself for testing

    memberstext are the same values but then send to a text field:

    Group name


    <small style="box-sizing:border-box;font-size:11.9px;"> Piet van der Ven</small>
    •  Henk de Vries
    •  Kees Jansma
    •  Piet van der Ven

    1715837278175409, 1715837270687920





    $api__body = @{
            type = "flexible_assets"
            attributes = @{
                organization_id = $api__org_id
                flexible_asset_type_id = $api_config.flexible_asset_type_id
                traits = @{
    				$api__key_name_group_name = $groupname
    				$api__key_name_members = $members
    				$api__key_name_members2 = $members2
    				$api__key_name_memberstext = $memberstext
    				$api__key_name_memberstext2 = $memberstext2

    I've tried string to integer but the value is to long 

    Cannot convert value "1715837270687920" to type "System.Int32". Error: "Value was either too large or too small for an Int32

    looking at values I've seen the brackets around members2 

    traits                         {members2, memberstext, members, memberstext2...}
    members2                       {1715837278175409, 1715837265510575, 1715837270687920}
    memberstext                    1715837278175409, 1715837265510575, 1715837270687920
    members                        1715837278175409, 1715837265510575, 1715837270687920
    memberstext2                   {1715837278175409, 1715837265510575, 1715837270687920}

    But doing $members = "{" + $members.TrimEnd(", ") + "}" results in an error from the webserver saying the value is wrong

    I'm a bit stuck on this one has someone got a solution?

    • Edited by 267522ilogic Wednesday, July 15, 2020 11:51 AM more info
    Wednesday, July 15, 2020 11:46 AM

All replies

  • hi 267522ilogic,

    i cannot get what you need and what problem is, but if you need get correct data type for your numbers you can get in a simple way

    $a = 1715837278175409

    The opinion expressed by me is not an official position of Microsoft

    Wednesday, July 15, 2020 12:07 PM
  • Did you try casting to int64? [int64]'1715837278175409'
    Wednesday, July 15, 2020 1:14 PM
  • Did you try casting to int64? [int64]'1715837278175409'

    what should i receive?

    ah sorry Leif-Arne I think you ask me :)

    The opinion expressed by me is not an official position of Microsoft

    • Edited by Vector BCO Wednesday, July 15, 2020 1:54 PM
    Wednesday, July 15, 2020 1:52 PM
  • Too much confusion about what a number is and what text is.  A web server cannot us numbers.  Webs only use text.  There are no numbers on teh Internet.  That is the whole point of HTTP and HTML.  How to get rid of numbers and still get the job done.

    A little time learning how to use the web and how to use a programming language to feed the web would help to solve your problem.

    You have your head backwards.  What you see in PowerShell is text on the screen but it is telling you that it is displaying numbers.  That is teh meaning of "{}".  This tells you an array.  In your case an array of numbers.  TO make them into text:

    $text = $arrayofnumbers -join ','


    Wednesday, July 15, 2020 5:18 PM
  • Hi,
    As this thread has been quiet for a while, so here is a quick question.Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Yang Yang

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, July 23, 2020 5:52 AM