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 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)
}