Select file on Import-Csv

后端 未结 3 1710
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-07 13:31

The code below is part of a switch and it\'s working fine, but the problem is: I need to change my file name to 15... Is it possible to to change it so that when I start it,

3条回答
  •  我在风中等你
    2021-01-07 13:55

    Below is my example.ps1 file that I use to write 1-off scripts. In your case I think you can get what you want with it. For example (no pun intended) you could call this script by typing

    C:\PathToYourScripts\example.ps1 [tab]
    

    where [tab] represents pressing the tab key. Powershell intellisense will kick in and offer autocompletion for file names. If your .csv file is not in the current director you can easily use Powershell intellisense to help you find it

    C:\PathToYourScripts\example.ps1  C:\PathToCSvFiles[tab]
    

    and powershell will autocomplete. Would-be-downvoters might notice that powershell autocomplete is definitely NOT a complete file-picker but this seems to fulfill the intent of the asked question. Here's the sample.

    <#
    .NOTES
        this is an example script
    .SYNOPSIS
        this is an example script
    .DESCRIPTION
        this is an example script
    
    .Example
        this is an example script
    .LINK
        https://my/_git/GitDrive
    #>
    [CmdletBinding(SupportsShouldProcess=$True, ConfirmImpact="Low")]
    param (
          [string] $fileName
    )
    Begin {
    }
    
    Process {
        if ($PSCmdlet.ShouldProcess("Simulated execution to process $($fileName):  Omit -Whatif to process ")) {
           Write-Information -Message "Processing $fileName" -InformationAction Continue
        }
    }
    
    End {
    }
    

    If you want to get autocomplete help for multiple parameters just type in the parameter name(s) and press [tab] after each one. Note that leaving the parameters blank will not break the script but you can either extend this to mark the parameters required or just fail with a helpful message. That seems a bit beyond the original question so I'll stop here.

提交回复
热议问题