{"id":1841,"date":"2011-11-18T16:33:49","date_gmt":"2011-11-18T21:33:49","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=1841"},"modified":"2011-11-18T16:33:49","modified_gmt":"2011-11-18T21:33:49","slug":"friday-fun-get-number-object","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/","title":{"rendered":"Friday Fun &#8211; Get Number Object"},"content":{"rendered":"<p>You most likely know that I'm all about the object and the PowerShell pipeline. Everything in PowerShell is an object. Pipe something to Get-Member and you can discover all of the object's properties and methods (ie its members). Some objects, like strings, have many methods but very few properties. Some objects, like numbers have very little of either. I mean, what can you really do with a number? Well, I can have a bit of fun with one and maybe teach a few PowerShell concepts along the way.<!--more--><\/p>\n<p>I wrote a function called Get-NumberObject. It will take any number you pass to it and create a custom number object. Here's an example of the end result:<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nPS S:\\> get-numberobject 7<\/p>\n<p>Log        : 1.94591014905531<br \/>\nTangent    : 0.871447982724319<br \/>\nInverse    : 0.142857142857143<br \/>\nCircleArea : 153.9380400259<br \/>\nIsEven     : False<br \/>\nIsPrime    : True<br \/>\nNumber     : 7<br \/>\nFactorial  : 5040<br \/>\nCosine     : 0.753902254343305<br \/>\nExp        : 1096.63315842846<br \/>\nSqrt       : 2.64575131106459<br \/>\nSine       : 0.656986598718789<br \/>\nSquare     : 49<br \/>\nCube       : 343<br \/>\nFactors    : {1, 7}<br \/>\n[\/cc]<\/p>\n<p>What I'm really doing is having some fun with the [Math] .NET class. This class has a number of methods for performing an operation on a number such as calculating its square root.  Here's the code and then I'll go through a few key points.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nFunction Get-NumberObject {<\/p>\n<p>Param(<br \/>\n[Parameter(Position=0,Mandatory=$True,HelpMessage=\"Enter an number greater than 0\",<br \/>\nValueFromPipeline=$True)]<br \/>\n[alias(\"x\")]<br \/>\n[ValidateScript({$_ -gt 0})]<br \/>\n[object[]]$Number,<br \/>\n[scriptblock]$Custom<br \/>\n)<\/p>\n<p>Begin {<\/p>\n<p>    Function Test-IsEven {<\/p>\n<p>    Param($x)<\/p>\n<p>        if ($x%2 -eq 0) {<br \/>\n          $True<br \/>\n        }<br \/>\n        else {<br \/>\n          $False<br \/>\n        }<\/p>\n<p>    } #Test-IsEven<\/p>\n<p>    Function Test-IsPrime {<br \/>\n    #http:\/\/www.wikihow.com\/Check-if-a-Number-Is-Prime<br \/>\n    Param($x)<\/p>\n<p>        if ($x -eq 1) {<br \/>\n            Write $False<br \/>\n        }<br \/>\n        Else {<br \/>\n            $Prime=$True<\/p>\n<p>            for ($i=2;$i -le ([math]::Sqrt($x));$i++) {<br \/>\n              $z=$x\/$i<br \/>\n              if ($z -is [int]) {<br \/>\n                $Prime=$False<br \/>\n                Break<br \/>\n              }<br \/>\n            } #for<br \/>\n            Write $Prime<br \/>\n        } #else<\/p>\n<p>    } #test-isprime<\/p>\n<p>} #begin<\/p>\n<p>Process {<br \/>\n foreach ($N in $number) {<br \/>\n    #define a hash table of values from some math operations<br \/>\n    $hash=@{<br \/>\n     Number=$N<br \/>\n     Square=($N*$N)<br \/>\n     Cube=[math]::Pow($N,3)<br \/>\n     Sqrt=[math]::Sqrt($N)<br \/>\n     Log=[math]::Log($N)<br \/>\n     Sine=[math]::Sin($N)<br \/>\n     Cosine=[math]::Cos($N)<br \/>\n     Tangent=[math]::Tan($N)<br \/>\n     CircleArea=[math]::PI*($N*$N)<br \/>\n     Inverse=1\/$N<br \/>\n     IsEven=(Test-IsEven $N)<br \/>\n     IsPrime=(Test-IsPrime $N)<br \/>\n     Exp=[math]::Exp($N)<br \/>\n     Factorial= (1..$N |foreach -begin {$r=1} -process {$r*=$_} -end {$r})<br \/>\n     Factors=(1..$N | where {$N\/$_ -is [int]})<br \/>\n    }<\/p>\n<p>    #if a custom calculation was passed, invoke it and add the value to the hash table<br \/>\n    if ($Custom) {<br \/>\n       $hash.Add(\"Custom\",(Invoke-Command -ScriptBlock $custom -ArgumentList $N))<br \/>\n    }<\/p>\n<p>    #use the hash tables as proprties for an object<br \/>\n    $obj=New-Object -TypeName PSObject -Property $hash<\/p>\n<p>    #let's add some methods<br \/>\n    $obj | Add-Member -MemberType ScriptMethod -Name ToBinary -value {[convert]::ToString($this.number,2)}<br \/>\n    $obj | Add-Member -MemberType ScriptMethod -Name ToOctal -value {[convert]::ToString($this.number,8)}<br \/>\n    $obj | Add-Member -MemberType ScriptMethod -Name ToHex -value {[convert]::ToString($this.number,16)} -PassThru<\/p>\n<p>  } #foreach<br \/>\n} #process<\/p>\n<p>End {<br \/>\n    #this is not used<br \/>\n}<\/p>\n<p>} #end function<br \/>\n[\/cc]<\/p>\n<p>The function takes a number as a parameter. I'll come back to the Custom parameter in a bit. The function includes two nested functions to determine if a number is even and one to determine if it is prime. Feel free to write you own algorithms but these work reasonable well. The main part of the function creates a custom object. The object's properties are common math operations.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n#define a hash table of values from some math operations<br \/>\n    $hash=@{<br \/>\n     Number=$N<br \/>\n     Square=($N*$N)<br \/>\n     Cube=[math]::Pow($N,3)<br \/>\n     Sqrt=[math]::Sqrt($N)<br \/>\n     Log=[math]::Log($N)<br \/>\n     Sine=[math]::Sin($N)<br \/>\n     Cosine=[math]::Cos($N)<br \/>\n     Tangent=[math]::Tan($N)<br \/>\n     CircleArea=[math]::PI*($N*$N)<br \/>\n     Inverse=1\/$N<br \/>\n     IsEven=(Test-IsEven $N)<br \/>\n     IsPrime=(Test-IsPrime $N)<br \/>\n     Exp=[math]::Exp($N)<br \/>\n     Factorial= (1..$N |foreach -begin {$r=1} -process {$r*=$_} -end {$r})<br \/>\n     Factors=(1..$N | where {$N\/$_ -is [int]})<br \/>\n    }<br \/>\n[\/cc]<\/p>\n<p>I'm going to trust that you have enough math background to understand the different operations. The end result is a hash table that I will use as property names and values.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n#use the hash tables as proprties for an object<br \/>\n    $obj=New-Object -TypeName PSObject -Property $hash<br \/>\n[\/cc]<\/p>\n<p>I also added a parameter called -Custom. This parameter expects a scriptblock like this:<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n {Param($x) [math]::Pow(10,$x)}<br \/>\n[\/cc]<\/p>\n<p>The scriptblock should take a value as a parameter because whatever number you pass to Get-NumberObject will be passed to this scriptblock.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n #if a custom calculation was passed, invoke it and add the value to the hash table<br \/>\n    if ($Custom) {<br \/>\n       $hash.Add(\"Custom\",(Invoke-Command -ScriptBlock $custom -ArgumentList $N))<br \/>\n    }<br \/>\n[\/cc]<\/p>\n<p>But wait...there's more! I thought, \"Don't try to do everything. What about adding some methods to the object?\" So I did. I took the custom object and piped it to Add-Member where I added a few ScriptMethods. The value of the scriptmethod is a scriptblock where you use $this to reference the object itself, not $_.  I created methods ToBinary(), ToOctal() and ToHex().<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n#let's add some methods<br \/>\n$obj | Add-Member -MemberType ScriptMethod -Name ToBinary -value {[convert]::ToString($this.number,2)}<br \/>\n$obj | Add-Member -MemberType ScriptMethod -Name ToOctal -value {[convert]::ToString($this.number,8)}<br \/>\n$obj | Add-Member -MemberType ScriptMethod -Name ToHex -value {[convert]::ToString($this.number,16)} -PassThru<br \/>\n[\/cc]<\/p>\n<p>Don't forget to add -Passthru to the last item, otherwise your object won't get written to the pipeline. But now I get a \"real\" object. GNO is an alias for my function.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno-300x205.png\" alt=\"\" title=\"Get-NumberObject Members\" width=\"300\" height=\"205\" class=\"aligncenter size-medium wp-image-1844\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno-300x205.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno-1024x699.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno.png 1172w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I can see the object:<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nPS S:\\> $n<\/p>\n<p>Log        : 2.56494935746154<br \/>\nTangent    : 0.46302113293649<br \/>\nInverse    : 0.0769230769230769<br \/>\nCircleArea : 530.929158456675<br \/>\nIsEven     : False<br \/>\nIsPrime    : True<br \/>\nNumber     : 13<br \/>\nFactorial  : 6227020800<br \/>\nCosine     : 0.907446781450196<br \/>\nExp        : 442413.39200892<br \/>\nSqrt       : 3.60555127546399<br \/>\nSine       : 0.420167036826641<br \/>\nSquare     : 169<br \/>\nCube       : 2197<br \/>\nFactors    : {1, 13}<br \/>\n[\/cc]<\/p>\n<p>I can even call the methods:<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nPS S:\\> $n.tobinary()<br \/>\n1101<br \/>\nPS S:\\> $n.tooctal()<br \/>\n15<br \/>\nPS S:\\> $n.tohex()<br \/>\nd<br \/>\n[\/cc]<\/p>\n<p>The bottom line is that I created a rich object that can be written to the pipeline.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nPS S:\\> 1..11 | get-numberobject | select Number,Sqrt,Square,Cube,Factorial | format-table -auto<\/p>\n<p>Number             Sqrt Square Cube Factorial<br \/>\n------             ---- ------ ---- ---------<br \/>\n     1                1      1    1         1<br \/>\n     2  1.4142135623731      4    8         2<br \/>\n     3 1.73205080756888      9   27         6<br \/>\n     4                2     16   64        24<br \/>\n     5 2.23606797749979     25  125       120<br \/>\n     6 2.44948974278318     36  216       720<br \/>\n     7 2.64575131106459     49  343      5040<br \/>\n     8 2.82842712474619     64  512     40320<br \/>\n     9                3     81  729    362880<br \/>\n    10 3.16227766016838    100 1000   3628800<br \/>\n    11  3.3166247903554    121 1331  39916800<br \/>\n[\/cc]<\/p>\n<p>If you aren't taking advantage of objects in the pipeline, then you might as well be writing VBScript. Look for objects. Find their members. And if you can't find an object that meets your need, create one!<\/p>\n<p>Download <a href='http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/Get-NumberObject.txt' target='_blank'>Get-NumberObject<\/a> and let me know what you think.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You most likely know that I&#8217;m all about the object and the PowerShell pipeline. Everything in PowerShell is an object. Pipe something to Get-Member and you can discover all of the object&#8217;s properties and methods (ie its members). Some objects, like strings, have many methods but very few properties. Some objects, like numbers have very&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[271,4,8],"tags":[139,230,32,144,534,540],"class_list":["post-1841","post","type-post","status-publish","format-standard","hentry","category-friday-fun","category-powershell","category-scripting","tag-add-member","tag-fridayfun","tag-functions","tag-objects","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun - Get Number Object &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun - Get Number Object &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"You most likely know that I&#039;m all about the object and the PowerShell pipeline. Everything in PowerShell is an object. Pipe something to Get-Member and you can discover all of the object&#039;s properties and methods (ie its members). Some objects, like strings, have many methods but very few properties. Some objects, like numbers have very...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2011-11-18T21:33:49+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno-300x205.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun &#8211; Get Number Object\",\"datePublished\":\"2011-11-18T21:33:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/\"},\"wordCount\":999,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/11\\\/gno-300x205.png\",\"keywords\":[\"Add-Member\",\"FridayFun\",\"functions\",\"objects\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"Friday Fun\",\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/\",\"name\":\"Friday Fun - Get Number Object &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/11\\\/gno-300x205.png\",\"datePublished\":\"2011-11-18T21:33:49+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/11\\\/gno.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/11\\\/gno.png\",\"width\":\"1172\",\"height\":\"801\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1841\\\/friday-fun-get-number-object\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Friday Fun\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/friday-fun\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun &#8211; Get Number Object\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Friday Fun - Get Number Object &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun - Get Number Object &#8226; The Lonely Administrator","og_description":"You most likely know that I'm all about the object and the PowerShell pipeline. Everything in PowerShell is an object. Pipe something to Get-Member and you can discover all of the object's properties and methods (ie its members). Some objects, like strings, have many methods but very few properties. Some objects, like numbers have very...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/","og_site_name":"The Lonely Administrator","article_published_time":"2011-11-18T21:33:49+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno-300x205.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun &#8211; Get Number Object","datePublished":"2011-11-18T21:33:49+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/"},"wordCount":999,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno-300x205.png","keywords":["Add-Member","FridayFun","functions","objects","PowerShell","Scripting"],"articleSection":["Friday Fun","PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/","name":"Friday Fun - Get Number Object &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno-300x205.png","datePublished":"2011-11-18T21:33:49+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/11\/gno.png","width":"1172","height":"801"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1841\/friday-fun-get-number-object\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Friday Fun","item":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},{"@type":"ListItem","position":2,"name":"Friday Fun &#8211; Get Number Object"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":8400,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/","url_meta":{"origin":1841,"position":0},"title":"Friday Fun &#8211; Custom Grouping with PowerShell","author":"Jeffery Hicks","date":"May 14, 2021","format":false,"excerpt":"The other day I was answering a question in the PowerShell Facebook group. This person was getting data from Active Directory and trying to organize the results in a way that met his business requirements. My suggestion was to use Group-Object and a custom grouping property. I am assuming you\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":33,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/33\/use-internet-explorer-in-powershell\/","url_meta":{"origin":1841,"position":1},"title":"Use Internet Explorer in PowerShell","author":"Jeffery Hicks","date":"May 23, 2006","format":false,"excerpt":"Here's a PowerShell Script that demonstates how to create COM objects in PowerShell, in this case an Internet Explorer instance. The script then takes the output of the Get-Service cmdlet and writes the results to the IE window.# IEServiceList.ps1# Jeffery Hicks# http:\/\/jdhitsolutions.blogspot.com# http:\/\/www.jdhitsolutions.com# May 2006#Display all running services in an\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9229,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9229\/exposing-the-mystery-of-powershell-objects\/","url_meta":{"origin":1841,"position":2},"title":"Exposing the Mystery of PowerShell Objects","author":"Jeffery Hicks","date":"March 14, 2023","format":false,"excerpt":"A few weeks ago, I was working on content for a new PowerShell course for Pluralsight. The subject was objects. We all know the importance of working with objects in PowerShell. Hopefully, you also know that the output you get on your screen from running a PowerShell command is not\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/03\/2023-03-14_10-19-52.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/03\/2023-03-14_10-19-52.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2023\/03\/2023-03-14_10-19-52.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3073,"url":"https:\/\/jdhitsolutions.com\/blog\/friday-fun\/3073\/friday-fun-view-objects-in-a-powershell-gridlist\/","url_meta":{"origin":1841,"position":3},"title":"Friday Fun: View Objects in a PowerShell GridList","author":"Jeffery Hicks","date":"May 24, 2013","format":false,"excerpt":"One of the things that makes PowerShell easy to learn is discoverability. Want to know more about a particular type of object? Pipe it to Get-Member. Or if you want to see values pipe it to Select-Object. get-ciminstance win32_computersystem | select * That's not too bad. Or you can pipe\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"Select-OutGridView","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/Select-OutGridView-300x72.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1603,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1603\/select-object-properties-with-values\/","url_meta":{"origin":1841,"position":4},"title":"Select Object Properties with Values","author":"Jeffery Hicks","date":"August 16, 2011","format":false,"excerpt":"Here's another concept I know I've written about in the past but that needed an update. A common technique I use when exploring and discovering objects is to pipe the object to Select-Object specifying all properties, get-service spooler | select *. There's nothing wrong with this approach but depending on\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6855,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6855\/powershell-scripting-for-linux-is-still-about-the-objects\/","url_meta":{"origin":1841,"position":5},"title":"PowerShell Scripting for Linux is Still About the Objects","author":"Jeffery Hicks","date":"October 8, 2019","format":false,"excerpt":"I've been trying to increase my Linux skills, especially as I begin to write PowerShell scripts and tools that can work cross-platform. One very important concept I want to make sure you don't overlook is that even when scripting for non-Windows platforms, you must still be thinking about objects. The\u2026","rel":"","context":"In &quot;PowerShell 7&quot;","block_context":{"text":"PowerShell 7","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-7\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1841"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1841\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}