# Unable to create a  final object using classes

**URL:** <https://forums.powershell.org/t/unable-to-create-a-final-object-using-classes/7778>\
**Category:** PowerShell Help\
**Created:** [January 1, 2017, 8:29am UTC](https://forums.powershell.org/t/unable-to-create-a-final-object-using-classes/7778 "2017-01-01T08:29:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wei-yen-tan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/wei-yen-tan/32/91_2.png) [@wei-yen-tan](https://forums.powershell.org/u/wei-yen-tan)\
**Post date:** [January 1, 2017, 8:29am UTC](https://forums.powershell.org/t/unable-to-create-a-final-object-using-classes/7778/1 "2017-01-01T08:29:52Z")

</div>

I decided to have a deep dive into learning classes and started looking at the Powershell Unplugged 2016 with Don Jones and Jeffrey Snover.

I decided to start by doing something simple. Use a restful api to grab info about the WAN ip. In this case i am using [http://ip-api.com](http://ip-api.com) to get the details. I have created my class just like what its in the demo but it comes up with an error to say that

```
value of type 
"System.Management.Automation.PSCustomObject" to type 
"Get-WhoisInformation.WhoisInformation"."
At line:58 char:3
+ Write-Output ([WhoisInformation]$object)
```

Any help appreciated. I am pretty sure it is something small I am missing. I am even happy if it is just guidance.

```
function Get-WhoisInformation
{

    
	[CmdletBinding()]
    [OutputType("WhoisInformation")]
	param
	(
		[Parameter(Mandatory = $false,
				   Position = 1)]
		[Alias('ipaddress')]
		[string]$domain
	)
	
	class WhoisInformation
	{
		[string]$city;
		[string]$country;
		[string]$countryCode;
		[string]$company;
        [string]$query;
		[string]$lat;
		[string]$lon;
		[string]$region;
		[string]$timezone;
		[string]$zip;
	}
	
	Update-TypeData -TypeName WhoisInformation -MemberType ScriptProperty -MemberName Company -Value { $this.org } -Force
	Update-TypeData -TypeName WhoisInformation -MemberType ScriptProperty -MemberName domain -Value { $this.query } -Force
	Update-TypeData -TypeName WhoisInformation -DefaultDisplayPropertySet domain, Company, Timezone, City -DefaultDisplayProperty domain -DefaultKeyPropertySet domain -Force
	

	if ($domain)
	
	{
		$object = Invoke-RestMethod -Uri http://ip-api.com/json/$domain
	}
	else
	{
		$object = Invoke-RestMethod -uri http://ip-api.com/json/
	}
	
	
		
		Write-Output ([WhoisInformation]$object)

	
	

}
```

---

<div class="post-metadata">

**Author:** ![wei-yen-tan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/wei-yen-tan/32/91_2.png) [@wei-yen-tan](https://forums.powershell.org/u/wei-yen-tan)\
**Post date:** [January 1, 2017, 7:17pm UTC](https://forums.powershell.org/t/unable-to-create-a-final-object-using-classes/7778/2 "2017-01-01T19:17:44Z")

</div>

Hi guys,

I reviewed it again. Went through the webinar and the demo.

With a little bit of experimentation found out the reason why.

Reason why it failed is because in my classes, I did not include all the properties found in Invoke-Restmethod.

I used the tool Convert-ObjecttoClass and copied that. Applied it the same way that Jeffrey did and what do you know…it worked.  
So lesson to take away is that all properties need to be added to the class. Hope that helps.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/unable-to-create-a-final-object-using-classes/7778/3 "2024-05-16T20:39:41Z")

</div>


