사용자 지정 개체 배열을 이러한 개체를 추가 처리 할 수있는 함수에 전달하려고합니다. 사용자 지정 개체 배열을 함수에 전달
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
지금까지 그렇게 좋았다.
Function ShowAdapters($netAdapterListParam)
{
$netAdapterListParam | fl Name, DeviceName, Guid, SharingEnabled
}
를 그리고 난 이런 식으로 호출 :
ShowAdapters $netAdapterList
지금 나는이 같은 더미 기능을 만든 $ netAdapterList
에서 함수 통과를 호출 할
아무 것도 인쇄되지 않습니다.
는나는 함수의 서명을 변경하려고했지만 여전히 행운 :
Function ShowAdapters([Object[]]$netAdapterListParam)
Function ShowAdapters([Object]$netAdapterListParam)
Function ShowAdapters([PSObject[]]$netAdapterListParam)
Function ShowAdapters([array]$netAdapterListParam)
아무도 내가 잘못 알고? 함수 내에서 내 사용자 정의 객체에 어떻게 접근 할 수 있습니까?
답장을 보내 주셔서 감사합니다. PowerShell IDE에서 ShowAdapters 함수 내에서 중단 점을 설정하는 스크립트를 실행했습니다. 매개 변수 $ netAdapterListParam에는 실제로 예상되는 사용자 지정 개체가 있으므로 FL 커맨드 릿에 포함되도록이 문제를 좁혔습니다. – donhector
@donhector 필자에게 PowerShell Console/ISE v2.0 및 3.0에서 코드 작업 (질문에 따라 복사하여 붙여 넣기)을 수행합니다. Format-List cmdlet에는 문제가 없습니다. –