Function with UDTable Problem

Hi,
I will create a function which contains a UDTable but the paramenter (in this case $Servername)
isn’t available in the UDTable / Endpoint script block. What am I doing wrong?

function New-FunctionServerInfo {
param($Servername)
New-UdTable -Id "4815" -Title "Server Informationen" -Headers @(" ", " ") -Endpoint {
    
    $BootUpTime = Get-WMIObject -Class Win32_OperatingSystem -ComputerName $Servername
    $EnabledAdapters = (Get-wmiObject Win32_networkAdapterConfiguration -ComputerName $Servername | ?{$_.IPEnabled}) 
    $IPAddress = $EnabledAdapters.IPAddress | Where-Object { -not [String]::IsNullOrEmpty($_)}
    $IPAddress = [String]::Join(', ', $IPAddress)
      @{
          'Computer Name'         = $Servername
          'Betriebssystem'      = (Get-WmiObject Win32_OperatingSystem -ComputerName $Servername).Caption
          'Gesamt Speicher System (C:)' = (Get-WmiObject Win32_LogicalDisk -ComputerName $Servername -Filter "DeviceID = 'C:'").Size / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }
          'Freier Speicher System (C:)'  = (Get-WmiObject Win32_LogicalDisk -ComputerName $Servername -Filter "DeviceID = 'C:'").FreeSpace / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }
          'Letzter Start' = $($BootUpTime.ConvertToDateTime($BootUpTime.LastBootupTime))
          'IP Adresse' = "$IPAddress"
      }.GetEnumerator() | Sort-Object "Name" | Out-UDTableData -Property @("Name", "Value")

  }

}

thanks for your help!!

I was just looking through old posts, if you’ve not already got an answer to this…
-endpoints have a different scope, you’ll want to pass $servername into the endpoint via the -ArgumentList parameter, and then inside your endpoint use $ArgumentList[0] to obtain your value.

function New-FunctionServerInfo {
param($Servername)
New-UdTable -Id "4815" -Title "Server Informationen" -Headers @(" ", " ") -ArgumentList $servername -Endpoint {
$servername = $argumentlist[0]

$BootUpTime = Get-WMIObject -Class Win32_OperatingSystem -ComputerName $Servername
$EnabledAdapters = (Get-wmiObject Win32_networkAdapterConfiguration -ComputerName $Servername | ?{$_.IPEnabled}) 
$IPAddress = $EnabledAdapters.IPAddress | Where-Object { -not [String]::IsNullOrEmpty($_)}
$IPAddress = [String]::Join(', ', $IPAddress)
  @{
      'Computer Name'         = $Servername
      'Betriebssystem'      = (Get-WmiObject Win32_OperatingSystem -ComputerName $Servername).Caption
      'Gesamt Speicher System (C:)' = (Get-WmiObject Win32_LogicalDisk -ComputerName $Servername -Filter "DeviceID = 'C:'").Size / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }
      'Freier Speicher System (C:)'  = (Get-WmiObject Win32_LogicalDisk -ComputerName $Servername -Filter "DeviceID = 'C:'").FreeSpace / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }
      'Letzter Start' = $($BootUpTime.ConvertToDateTime($BootUpTime.LastBootupTime))
      'IP Adresse' = "$IPAddress"
  }.GetEnumerator() | Sort-Object "Name" | Out-UDTableData -Property @("Name", "Value")

  }

}
1 Like