Link to home
Create AccountLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

PowerShell: Display a gridview with an intial selector

Hello experts,

I have the following PowerShell, that allows me to display Office Shortcuts:

# ===========================================================================
# Author:
# Creation date: 2020/04/26 17:42:11
# Description: Display a grid view based on csv file
# ===========================================================================




$CurrentDir = Split-Path $script:MyInvocation.MyCommand.Path
#Example: $Root = $CurrentDir + '\Root2'
#Example: $FileVariable = Get-Content -Path "$($CurrentDir)\File.txt"


Function Out-GridViewCsv {
[CmdletBinding()]
Param(
   [Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
   [Alias('FullName')]
   [String[]]$Path,
   [Char]$Delimiter,
   [String]$Title,
   [Parameter(ParameterSetName='Wait')]
   [Switch]$Wait,
   [Parameter(ParameterSetName='OutputMode')]
   [ValidateSet('None', 'Single', 'Multiple')]
   [String]$OutputMode
)
   Begin {
      $splatImport = @{}
      If ($Delimiter) {$splatImport['Delimiter'] = $Delimiter}
      $splatGrid = @{}
      If ($Title) {$splatGrid['Title'] = $Title}
      If ($Wait) {$splatGrid['Wait'] = $Wait}
      If ($OutputMode) {$splatGrid['OutputMode'] = $OutputMode}
      $paths = New-Object -TypeName System.Collections.ArrayList
   }
   Process {
      $Path | ForEach-Object {
         Write-Verbose "Importing '$($_)' ..."
         [void]$paths.Add($_)
      }
   }
   End {
      If ($Wait) {
         Write-Warning "Waiting for confirmation of the GridView ..."
      }
      $paths | Import-Csv @splatImport | Out-GridView @splatGrid
   }
}


#First approach
#Get-ChildItem -Path "$($CurrentDir)\2.Files" -Filter shortcuts*.csv | Out-GridViewCsv -Delimiter ';' -Wait -Title 'Shortcuts'


#Second approach
$paths = @(
   "$($CurrentDir)\..\2.Shorcuts-files\excel-shortcuts.csv"
    "$($CurrentDir)\..\2.Shorcuts-files\powerpoint-shortcuts.csv"
   "$($CurrentDir)\..\2.Shorcuts-files\excel-vba-shortcuts.csv"
    "$($CurrentDir)\..\2.Shorcuts-files\outlook-shortcuts.csv"
    "$($CurrentDir)\..\2.Shorcuts-files\word-shortcuts.csv"


#   "$($CurrentDir)\..\2.Shorcuts-files\excel-vba-shortcuts.txt"
)
Out-GridViewCsv -Path $paths -Delimiter ';' -Wait -Title 'Shortcuts' -Verbose 

Open in new window

I started yesterday how to use PhotoShop and I would like to include the following

attach file:photoshop-shortcuts.csv


And I would like to have a selector in order to differentiate the Adobe and Office applications.


The idea is to have the following as initial UserForm:

Please select the shortcuts gridview app that you want to display:

(1) Adobe 

(2) Office

 I attach the current shortcuts files that I use for this gridview:

excel-shortcuts.csv

powerpoint-shortcuts.csv

excel-vba-shortcuts.csv

outlook-shortcuts.csv

word-shortcuts.csv



ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Luis Diaz

ASKER

Indeed, thank you for this valuable advice.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Great!