Out-Gridview -单击取消时窗口未关闭- PowerShell

2ledvvac  于 2023-04-06  发布在  Shell
关注(0)|答案(1)|浏览(173)

需要一点帮助来取消gridview时,点击取消,如果可能的话,打开一个较小的窗口(有很多空白的空间),此外,有时字符串是打开...并需要采取光标的权利,看到全名。
脚本从CSV中读取数据并相应地初始化变量

$Versions = Get-Content "$SharedDriveFolderPath\Versions\dataSource.csv"
    $Versions = $Versions | ConvertFrom-CSV -Del ";"

    do { $VersionToUse = $Versions.Sheetcol | Out-Gridview -Title "Choose version from the list" -PassThru } while ($Versions.Sheetcol -notcontains $VersionToUse)

    $Versionlocationforpatches = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).Versionlocationforpatches
    $Versionlocationforcabs = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).Versionlocationforcabs
    $ReleaseVersion = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).ReleaseVersion
    $Sourceversion = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).Sourceversion
    $LinkForVersion = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).LinkForVersion
    $VersionNumber = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).VersionNumber
    $buildver = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).buildver
    $PipelineID = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).PipelineID
    $xmlFilePath = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).xmlFilePath
    $Buildname = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).Buildname
    $Sheetcol = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).Sheetcol
    $QApath = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).QApath
    $Weekendversion = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).Weekendversion
    $BlockUpload = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).BlockUpload
    $PrepareCI = ($Versions | Where-Object { $_.Sheetcol -eq $VersionToUse }).PrepareCI

这是一个输出窗口:

下面是csv的样子:窗口中的每一行代表csv中的一行。

ReleaseVersion;Sourceversion;Versionlocationforpatches;Versionlocationforcabs;LinkForVersion;VersionNumber;buildver;PipelineID;xmlFilePath;Buildname;Sheetcol;QApath;Weekendversion;BlockUpload;PrepareCI
    8.5.34.31.6;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.5.34.31;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.5.34.31\Installer\Patches;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.5.34.31\Installer;\\global\builds\Releases\RingOne Builds\8.5 RingOne\8.5.34.31.6;8.5.34.31;8.5.34.31;18710;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.5.34.31\BuildDescription.xml;8.5.34.31.5;8.5.34 Side VIP CU4;\\global\QA\AgileTeam\Ziv\Builds\8.5.34.31-CU4;;;
    8.5.34.35.6;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.5.34.35;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.5.34.35\Installer\Patches;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.5.34.35\Installer;\\global\builds\Releases\RingOne Builds\8.5 RingOne\8.5.34.35.6;8.5.34.35_Federal;8.5.34.35;18713;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.5.34.35\BuildDescription.xml;Side VIP for 8.5.34.35_Federal;8.5.34.35 Side VIP Federal;\\global\QA\AgileTeam\Ziv\Builds\8.5.34.35_GA_Federal;;;
    8.6.22.607.40;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.22.607;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.22.607\Installer\Patches;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.22.607\Installer;\\global\builds\Releases\RingOne Builds\8.6 RingOne\8.6.22.607.40;8.6.22.607;8.6.22.607;26845;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.22.607\BuildDescription.xml;Side VIP for 8.6.22.607;8.6.22 Side VIP + CU6;\\global\QA\AgileTeam\Ziv\Builds\8.6.22.607;8.6.22.607.32;BlockUpload.txt;22212
    8.6.22.2000.38;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.22.2000;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.22.2000\Installer\Patches;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.22.2000\Installer;\\global\builds\Releases\RingOne Builds\8.6 RingOne\8.6.22.2000.38;8.6.22.2000_Federal;8.6.22.2000;27970;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.22.2000\BuildDescription.xml;Side VIP for 8.6.22.2000_Federal;8.6.22 Side VIP Federal;\\global\QA\AgileTeam\Ziv\Builds\8.6.22.2000_Federal;;BlockUpload_Federal.txt;22212
    8.6.32.236.4;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.32.236;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.32.236\Installer\Patches;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.32.236\Installer;\\global\builds\Releases\RingOne Builds\8.6 RingOne\8.6.32.236.4;8.6.32.236;8.6.32.236;26845;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.32.236\BuildDescription.xml;Side VIP for 8.6.32.236;8.6.32 Side VIP;\\global\QA\AgileTeam\Ziv\Builds\8.6.32.236;8.6.32.236.1;BlockUpload.txt;22212
    8.6.32.2002.5;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.32.2002;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.32.2002\Installer\Patches;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.32.2002\Installer;\\global\builds\Releases\RingOne Builds\8.6 RingOne\8.6.32.2002.5;8.6.32.2002;8.6.32.2002;27970;\\global\Engineering\Builds\Agile\SideVIP\Versions\8.6.32.2002\BuildDescription.xml;Side VIP for 8.6.32.2002;8.6.32 Side VIP Federal;\\global\QA\AgileTeam\Ziv\Builds\8.6.32.2002;8.6.32.2002.1;BlockUpload_Federal.txt;22212
ugmeyewa

ugmeyewa1#

如果你把csv作为一个对象导入并使用表单,你可以给予自己更多的灵活性:

Add-Type -AssemblyName System.Windows.Forms -ErrorAction Stop

$Versions = Import-Csv -Path c:\temp\tempdata.csv -Delimiter ';'

$form = New-Object System.Windows.Forms.Form
$form.Text = "Select Version"
$form.Size = '250,220'
$form.StartPosition = 'CenterScreen'
$form.MaximizeBox = $false

# Listview box to display version
$DevListBox = New-Object System.Windows.Forms.ListView
$DevListBox.View = [System.Windows.Forms.View]::Details
$DevListBox.Location = '15,15'
$DevListBox.Size = '200,150'
$DevListBox.Columns.Add('SheetCol',180) | Out-Null
# Can add more columns as required
# $DevListBox.Columns.Add('PrepareCI',180) | Out-Null
$DevListBox.FullRowSelect = $true

$form.Controls.Add($DevListBox)

#PopulateListView
$Versions | ForEach-Object {
    $Entry = New-Object System.Windows.Forms.ListViewItem($_.sheetcol) -ErrorAction Stop
    # You could add more fields as subitems if required, you need to add columns to the $DevListBox object if you want them displayed
    # $Entry.SubItems.Add($_.PrepareCI) | Out-Null
$DevListBox.Items.Add($Entry) | Out-Null
}

#Carry out actions when form closes
$form.Add_FormClosing({
    # Find the data corresponding to the selected item when the form closed 
    $SelectedItem = $Versions | Where-Object { $_.sheetcol -eq $DevListBox.SelectedItems[0].Text }
    # You could use this object directly, but assigning the values to your variables for direct comparison with your example
    $SelectedItem.PSObject.Properties | ForEach-Object {
        # Please read up about scopes - could use global here if needed
        Try {
            New-Variable -Name $_.Name -Value $_.Value -Scope Script -ErrorAction Stop
        }
        Catch {
        }
    }
})
#

# Show form
$form.ShowDialog() | Out-Null
$form.Dispose()

相关问题