カスタムオブジェクトの配列を関数に渡して、これらのオブジェクトをさらに処理しようとしています。
カスタムオブジェクト配列を作成する関数は次のとおりです。
Function GetNetworkAdapterList
{
# Get a list of available Adapters
$hnet = New-Object -ComObject HNetCfg.HNetShare
$netAdapters = @()
foreach ($i in $hnet.EnumEveryConnection)
{
$netconprop = $hnet.NetConnectionProps($i)
$inetconf = $hnet.INetSharingConfigurationForINetConnection($i)
$netAdapters += New-Object PsObject -Property @{
Index = $index
Guid = $netconprop.Guid
Name = $netconprop.Name
DeviceName = $netconprop.DeviceName
Status = $netconprop.Status
MediaType = $netconprop.MediaType
Characteristics = $netconprop.Characteristics
SharingEnabled = $inetconf.SharingEnabled
SharingConnectionType = $inetconf.SharingConnectionType
InternetFirewallEnabled = $inetconf.InternetFirewallEnabled
SharingConfigurationObject = $inetconf
}
$index++
}
return $netAdapters
}
次に、メインコードで、上記の関数を次のように呼び出します。
$netAdapterList = GetNetworkAdapterList
$ netAdapterListは期待されるデータを返し、次のようなことができます。
$netAdapterList | fl Name, DeviceName, Guid, SharingEnabled
ここまでは順調ですね。
ここで、$netAdapterListを渡す関数を呼び出します。
次のようなダミー関数を作成しました。
Function ShowAdapters($netAdapterListParam)
{
$netAdapterListParam | fl Name, DeviceName, Guid, SharingEnabled
}
そして、私がこのようにそれを呼び出すとき:
ShowAdapters $netAdapterList
何も印刷されません。
関数のシグネチャを変更しようとしましたが、それでもうまくいきません。
Function ShowAdapters([Object[]]$netAdapterListParam)
Function ShowAdapters([Object]$netAdapterListParam)
Function ShowAdapters([PSObject[]]$netAdapterListParam)
Function ShowAdapters([array]$netAdapterListParam)
誰かが私が間違っていることを知っていますか?関数内のカスタムオブジェクトにアクセスするにはどうすればよいですか?