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下拉列表选择项,将特定文本文件加载到表单上的文本框中_Powershell_Dropdown - Fatal编程技术网

Powershell下拉列表选择项,将特定文本文件加载到表单上的文本框中

Powershell下拉列表选择项,将特定文本文件加载到表单上的文本框中,powershell,dropdown,Powershell,Dropdown,在Powershell中,我希望有一个包含以下项目的下拉列表: 文本文件1 文本文件2 文本文件3 如果选择了列表项,则会将文件内容读入表单上的文本框中 例如: 选择下拉列表“Textfile1”,将c:\Textfile1.txt加载到表单上的文本框中 已经使用if/elseif尝试了一个函数,但很难将其绑定在一起,不幸的是,仍然在学习Powershell。我不建议创建一个带有下拉列表的表单并从中返回选择,因为Powershell基本上不是为这些东西而构建的 当然,我不认为这是不可能的,但在这

在Powershell中,我希望有一个包含以下项目的下拉列表:

文本文件1 文本文件2 文本文件3

如果选择了列表项,则会将文件内容读入表单上的文本框中

例如:

选择下拉列表“Textfile1”,将c:\Textfile1.txt加载到表单上的文本框中


已经使用
if/elseif
尝试了一个函数,但很难将其绑定在一起,不幸的是,仍然在学习Powershell。

我不建议创建一个带有下拉列表的表单并从中返回选择,因为Powershell基本上不是为这些东西而构建的

当然,我不认为这是不可能的,但在这种情况下,我会使用Out GridView函数来完成与您的需求类似的工作

$files_location = "C:\yourlocation\*"


$options = Get-ChildItem $files_location


$user_choice = $options | Out-GridView -Title 'Select the File you want to show'  -PassThru

Switch ($user_choice)  {

    #Condition to check:

    { $user_choice.Name -eq 'textfile1.txt' }


    #Do something:
    {
        Write-Host "Im going to open $($user_choice.Name)"
        #Open the file:
        start "$user_choice"
    }

    #Continue your switch/case conditions here...

}
我正在使用Get ChildItem函数中的输出对象,并从中输出一个gridview

如果您更熟悉此功能,则可以将开关盒更改为if语句

$files_location = "C:\yourlocation\*"


$options = Get-ChildItem $files_location


$user_choice = $options | Out-GridView -Title 'Select the File you want to show'  -PassThru

if ($user_choice.Name -eq 'a.txt')
{
    start $user_choice
}

请分享你尝试的代码谢谢你这很好!如何使这部分也成为动态的?如果($user_choice.Name-eq'a.txt')。我不想硬编码“a.txt”文件名和-eq,然后使用验证它是否匹配来做一些事情。基本上,任何文件都会被选中,然后显示出来,但每个文件都不会有不同的条件(尽管我很欣赏这个示例,因为它在后面会很有用),我想它应该是{$user\u choice.name-eq'a.txt'{$user\u choice.Name-eq“$(user\u choice.Name)”}