PowerShell Static Methods; "Missing '(' in class method parameter list"

Viewed 78
class HostDataRetriever {

static [hashtable] Get-HostData() {
    [string]$OS = Get-CimInstance -Class Win32_ComputerSystem | Select-Object Name
    [string]$IP = Get-NetIPAddress | Where-Object { ($_.InterfaceAlias -eq "Ethernet") -and ($_.AddressState -eq "Preferred") } | Select-Object IPv4Address
    [array]$Software = Get-CimInstance -Class Win32_Product | Select-Object name
    return @{
        "name" = $env:COMPUTERNAME
        "OS" = $OS
        "IP" = $IP
        "Software" = $Software
    }
}

}

Hi, I don't get what i'm doing wrong syntactically; i get 3 Errors:

  • "Missing '(' in class method parameter list"
  • "Missing function body in function declaration"
  • Unexpected token '}' in expression or statement
0 Answers
Related