Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PowerShell和映射驱动器中读取CSV_Powershell_Import Csv - Fatal编程技术网

在PowerShell和映射驱动器中读取CSV

在PowerShell和映射驱动器中读取CSV,powershell,import-csv,Powershell,Import Csv,我希望从.CSV读取数据,然后使用数据映射驱动器。该文件如下所示: Location, UNC1, UNC2 USA, \\Server1\Data, \\Server1\Shared EMEA, \\Server2\Data, \\Server2\Shared 棘手的部分是我想从CSV读取数据,然后显示在列表框中(猜我必须调用VBS?),但只显示框中的区域。然后,当我选择区域时,它将2个UNC映射到本地机器 我已经读了一些帖子,需要导入CSV——只是寻找一个起点 有什么建议吗?通

我希望从.CSV读取数据,然后使用数据映射驱动器。该文件如下所示:

Location, UNC1, UNC2      
USA, \\Server1\Data, \\Server1\Shared
EMEA, \\Server2\Data, \\Server2\Shared
棘手的部分是我想从CSV读取数据,然后显示在列表框中(猜我必须调用VBS?),但只显示框中的区域。然后,当我选择区域时,它将2个UNC映射到本地机器

我已经读了一些帖子,需要导入CSV——只是寻找一个起点


有什么建议吗?

通常我们会要求您自己尝试做一些事情,然后我们会在这里帮助您解决问题。下次当你问问题时,请尝试自己编写代码,然后在遇到困难时寻求帮助

我这么做只是为了好玩,很快,因为这很简单,享受吧

function Map-Drive(){
    if($ComboBox1.text -eq "USA"){
        New-PSDrive -Name K -PSProvider FileSystem -Root $csv.UNC1[0] -Persist -Scope Global
        New-PSDrive -Name L -PSProvider FileSystem -Root $csv.UNC2[0] -Persist -Scope Global
    }
    if($ComboBox1.text -eq "EMEA"){
        New-PSDrive -Name M -PSProvider FileSystem -Root $csv.UNC1[1] -Persist -Scope Global
        New-PSDrive -Name N -PSProvider FileSystem -Root $csv.UNC2[1] -Persist -Scope Global
    }
}

$csv = import-csv "\\server\folder\test.csv" -Delimiter ","

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form                            = New-Object system.Windows.Forms.Form
$Form.ClientSize                 = '319,63'
$Form.text                       = "Regional Drive Map"
$Form.TopMost                    = $false

$ComboBox1                       = New-Object system.Windows.Forms.ComboBox
$ComboBox1.text                  = "comboBox"
$ComboBox1.BackColor             = "#d7ebff"
$ComboBox1.width                 = 143
$ComboBox1.height                = 54
$ComboBox1.location              = New-Object System.Drawing.Point(20,18)
$ComboBox1.Font                  = 'OCR A,12,style=Bold'

$Button1                         = New-Object system.Windows.Forms.Button
$Button1.BackColor               = "#eaeaea"
$Button1.text                    = "Map Drive"
$Button1.width                   = 107
$Button1.height                  = 30
$Button1.location                = New-Object System.Drawing.Point(174,14)
$Button1.Font                    = 'OCR A,10'

$ComboBox1.DataSource = [system.Collections.ArrayList]$csv
$ComboBox1.DisplayMember = 'Location'

$Button1.Add_Click({Map-Drive})

$Form.controls.AddRange(@($ComboBox1,$Button1))
#Finally Show our GUI
$Form.ShowDialog()

检查欢迎访问SO!请检查并编辑您的问题。请提供您尝试过的代码。感谢您的努力-我只是在寻找一个起点。我有一个脚本,有人用VB写的,想移植到PS。