Samples/ImportCallhomeDetails/InFile/device.ps1

# ------------------------------------------------------------------
# Lenovo Copyright
#
# (C) Copyright Lenovo 2024 - present.
#
# LIMITED AND RESTRICTED RIGHTS NOTICE:
# If data or software is delivered pursuant a General Services
# Administration (GSA) contract, use, reproduction, or disclosure
# is subject to restrictions set forth in Contract No. GS-35F-05925.
# ------------------------------------------------------------------

class Device
{
    [string] $serverName
    [string] $serialNumber
    [bool] $isManaged = $false
    [string] $id
    [object] $groups = $null
    [string] $addressHash
    [string] $groupID = $null
}

class ContactInfo
{
    [string] $fullName = [System.string]::Empty
    [string] $contactEmail = [System.string]::Empty
    [string] $contactPhone = [System.string]::Empty
    [string] $companyName = [System.string]::Empty
    [string] $streetAddress = [System.string]::Empty
    [string] $city = [System.string]::Empty
    [string] $stateProvince = [System.string]::Empty
    [string] $country = [System.string]::Empty # country code
    [string] $postalCode = [System.string]::Empty
    [string] $preferredContactMethod = [System.String]::Empty
}

class DeviceAddress : ContactInfo
{
    [string] $countryName = [System.string]::Empty
    [string] $id = [System.String]::Empty
    [string] $groupID = $null
    [bool] $exists = $false

    [ContactInfo] GetContactInfo()
    {
        [ContactInfo] $contact = [ContactInfo]::new()
        $contact.city = $this.city
        $contact.fullName = $this.fullName
        $contact.contactEmail = $this.contactEmail
        $contact.contactPhone = $this.contactPhone
        $contact.companyName = $this.companyName
        $contact.streetAddress = $this.streetAddress
        $contact.stateProvince = $this.stateProvince
        $contact.country = $this.country
        $contact.postalCode = $this.postalCode
        $contact.preferredContactMethod = $this.preferredContactMethod
        return $contact
    }

    [bool] IsValid()
    {
        return (-not `
        ( [System.String]::IsNullOrWhiteSpace($this.postalCode) `
          -or `
          [System.String]::IsNullOrWhiteSpace($this.stateProvince) `
          -or `
          [System.String]::IsNullOrWhiteSpace($this.streetAddress) `
          -or `
          [System.String]::IsNullOrWhiteSpace($this.city) `
          -or `
          [System.String]::IsNullOrWhiteSpace($this.countryName)  `
          -or`
          [System.String]::IsNullOrWhiteSpace($this.country) `
        ))
    }

    [string] GetAddressHash()
    {
        [string] $mystring = `
        $this.city.Trim() + "|" + $this.contactEmail.Trim() + "|" + $this.contactPhone.Trim() + "|" + `
        $this.country.Trim() + "|" + $this.countryName.Trim() + "|" + $this.fullName.Trim() + "|" + `
        $this.postalCode.Trim() + "|" + $this.stateProvince.Trim() + "|" + $this.streetAddress.Trim()
        [System.Text.UTF8Encoding] $utf8 = [System.Text.UTF8Encoding]::new()
        $mystream = [IO.MemoryStream]::new($utf8.GetBytes($mystring.ToCharArray()))
        $hash = Get-FileHash -InputStream $mystream -Algorithm SHA256
        $mystream.Close()
        $mystream.Dispose()
        return $hash.Hash
    }
}

# EOF