Int64 object type length

369 views Asked by At

I am new to powershell so it would be great if someone could help me to understand best practice for this case:

I am using Centrify Powershell module to fetch users' uid property. If I type

Get-CdmUserProfile -Zone "DN_NAME_HERE" | select name,uid

It returns following:

markok                   3252423756
markusa                  32356514982
markusk                    417
markusp                  32187

I need to filter out uid length. so I tried

Get-CdmUserProfile -Zone "DN_NAME_HERE" | ? {($_.Uid).length -lt 6 } | select name,uid

but it keeps returning users with uid longer than 6 characters long. So I tried to find out the length of each uid:

Get-CdmUserProfile -Zone "DN_NAME_HERE" | %{($_.uid).length}

and

Get-CdmUserProfile -Zone "DN_NAME_HERE" | %{($_.uid).count}

but itreturns 1 for each uid which is obviously not true.

So I decided to find out the type of uid property by Get-CdmUserProfile -Zone "DN_NAME_HERE" | %{($_.uid).gettype()} and the object type is Int64 System.ValueType

I have managed to find a way around by using tostring() method:

Get-CdmUserProfile -Zone "DN_NAME_HERE" | %{(($_.uid).tostring()).length}

It does it's job, but I am not sure if it's the best practice in terms of performance and neat typing. Is there any other way of finding out int64 object length?

TL;DR

What is the best practice to find int64 length?

1

There are 1 answers

0
codewario On BEST ANSWER

You are doing it correctly, converting it to a string and getting the length.

If you really want a mathematical way to get the number of digits in an Integer, you can use the [Math]::Log10 function with the [Math]::Truncate function:

$digitsLong = [Math]::Truncate( [Math]::Log10( $uid ) + 1 )