[英]Problems with CSV in Powershell
I have imported a .csv file and i have the first column listed in a combobox in my form. 我已经导入了一个.csv文件,并且在表单的组合框中列出了第一列。 I am trying to match the the selected data from the combobox with the corresponding row. 我试图匹配从组合框中选择的数据与相应的行。 For Example 例如
Office,Server Chicago,chicago1 New York, newyork1 Los Angeles, la1 办公室,服务器芝加哥,芝加哥1纽约,纽约1洛杉矶,la1
When they select the $office, id like to create the next object the $server and reference it somewhere else. 当他们选择$ office时,id喜欢在$ server中创建下一个对象并在其他地方引用它。
$Offices = @(Import-CSV "C:\source\PrinterTable.csv")
$Array = $Offices.office | Sort-Object
ForEach ($Choice in $Array) {
[void] $objListBox.Items.Add($Choice)
}
$handler_Office_Click=
{
$officeSelected = $objListBox.SelectedItem
$row = $officeSelected | where { $_.office -eq $officeSelected }
$server = $row.server
explorer.exe \\$server
}
I've been googling for hours... please help! 我已经搜寻了几个小时...请帮忙!
When you have a selected office name, find a row in $offices
that has a matching office
field. 选定办公室名称后,请在$offices
中找到具有匹配office
字段的行。 Then select server
field from this row. 然后从此行中选择server
字段。
$row = $offices | where { $_.office -eq $office }
$server = $row.server
run a foreach
loop to read each line from the csv till you find the $office
you want. 运行foreach
循环从csv中读取每一行,直到找到所需的$office
。
Foreach ($line in $offices) {
If ($line.office -eq $office) {
$server = $line.server
}
}
So i figured out the fix, i had to bring my csv back to my $handler click, final code is 所以我想出了解决办法,我不得不将csv带回到$ handler点击,最终代码是
$handler_Office_Click=
{
$officeSelected = $objListBox.SelectedItem
$OffServer= ($PrinterTables | where {$_.office -eq $officeSelected}).server
explorer.exe \\$OffServer
}
$PrinterTables = @(Import-CSV "C:\Program Files (x86)\Helpdesk 2.0\PrinterTables.csv")
$ListedOffices = $PrinterTables.office | Sort-Object
ForEach ($Choice in $ListedOffices) {
[void] $objListBox.Items.Add($Choice)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.