가져 오기를 시도한 다음 해당 목록을 드롭 다운 상자에서 사용하려고하는 CSV 속성이 있습니다. 드롭 다운에는 문자열이 필요하지만 목록으로 변환하는 모든 작업이 실패했습니다. 여기에 내가 무엇을 가지고 :CSV 가져 오기 및 목록으로 변환 할 속성 가져 오기
$roles = (Import-CSV "\\Networklocation\somefile.csv" | Select ProjectRoleProfile | Where { $_.ProjectRoleProfile -ne "" }).ProjectRoleProfile # Selecting my attribute and cleaning out the empty cells
foreach ($role in $roles)
{
$role = [string]$role
Write-Host $role
Update-ComboBox $role #Function that updates my drop down box. Functions as long as I get strings.
}
오류 :
ERROR: Update-ComboBox : Cannot process argument transformation on parameter 'ComboBox'. Cannot convert the "MYData" value of type "System.String" to type
ERROR: "System.Windows.Forms.ComboBox".
MyFile.ps1 (97, 18): ERROR: At Line: 97 char: 18
ERROR: + Update-ComboBox $role
ERROR: + ~~~~~
ERROR: + CategoryInfo : InvalidData: (:) [Update-ComboBox], ParameterBindingArgumentTransformationException
ERROR: + FullyQualifiedErrorId : ParameterArgumentTransformationError,Update-ComboBox
ERROR:
내 생각 엔 내가 작은 뭔가를 놓치고 있다는 것입니다. 어떤 도움을 주셔서 감사합니다.
편집 : 업데이트-콤보 상자 데이터의
function Update-ComboBox
{
<#
.SYNOPSIS
This functions helps you load items into a ComboBox.
.DESCRIPTION
Use this function to dynamically load items into the ComboBox control.
.PARAMETER ComboBox
The ComboBox control you want to add items to.
.PARAMETER Items
The object or objects you wish to load into the ComboBox's Items collection.
.PARAMETER DisplayMember
Indicates the property to display for the items in this control.
.PARAMETER Append
Adds the item(s) to the ComboBox without clearing the Items collection.
.EXAMPLE
Update-ComboBox $combobox1 "Red", "White", "Blue"
.EXAMPLE
Update-ComboBox $combobox1 "Red" -Append
Update-ComboBox $combobox1 "White" -Append
Update-ComboBox $combobox1 "Blue" -Append
.EXAMPLE
Update-ComboBox $combobox1 (Get-Process) "ProcessName"
.NOTES
Additional information about the function.
#>
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNull()]
[System.Windows.Forms.ComboBox]
$ComboBox,
[Parameter(Mandatory = $true)]
[ValidateNotNull()]
$Items,
[Parameter(Mandatory = $false)]
[string]
$DisplayMember,
[switch]
$Append
)
if (-not $Append)
{
$ComboBox.Items.Clear()
}
if ($Items -is [Object[]])
{
$ComboBox.Items.AddRange($Items)
}
elseif ($Items -is [System.Collections.IEnumerable])
{
$ComboBox.BeginUpdate()
foreach ($obj in $Items)
{
$ComboBox.Items.Add($obj)
}
$ComboBox.EndUpdate()
}
else
{
$ComboBox.Items.Add($Items)
}
$ComboBox.DisplayMember = $DisplayMember
스크린 샷
코드 : 나는 모든 민감한 정보를 어떻게 표시 할 수 없습니다하지만 난 ProjectRoleProfile 열을 얻기 위해 노력하고
'$ roles'의 내용은 무엇입니까? Powershell 커맨드 라인에서'$ roles = (Import-CSV "\\ Networklocation \ somefile.csv"| Select Attribute | Where {$ _. Attribute -ne ""}). – t0mm13b
@ t0mm13b 내가 찾는 것에 대한 목록입니다. 흥미로운 점은 GM을 실행하지 않았다는 것입니다. 그냥 그렇게했고 TypeName : System.String을 얻었습니다. 왜 그것이 질식하는지 잘 모르겠다 – EvanM
@BenH - 감사합니다. – EvanM