在Import-Csv上选择文件 [英] Select file on Import-Csv
问题描述
下面的代码是开关的一部分,它可以正常工作,但是问题是:我需要将文件名更改为15 ...是否可以更改它,以便在我启动它时等待使用Tab键选择文件?类似于在PowerShell控制台中编写Import-Csv
并按 Tab 时,它会显示所有可能的路径和文件.
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, it waits to select for a file with the tab key? Something like when you write Import-Csv
in a PowerShell console and press Tab it shows all possbile paths and files.
$names = Import-Csv 15.csv -Header Givenname,Surname -Delimiter ";"
Write-Host "Rename your csv file to '15' and put it in same folder with this script" -ForegroundColor Cyan
pause
foreach ($Name in $Names) {
$FirstFilter = $Name.Givenname
$SecondFilter = $Name.Surname
Get-ADUser -Filter {GivenName -like $FirstFilter -and Surname -like $SecondFilter} |
select Enabled, SamAccountName, DistinguishedName,
@{n="ou";e={($_.DistinguishedName -split ",*..=")[2]}} |
Export-Csv .\sam.csv -NoTypeInformation -Append
}
推荐答案
因此,您希望在脚本中使用Intellisense.雄心勃勃的举动.大多数人会满足于file browser dialog box
.无论如何,我将不得不把你推荐给比我聪明的人.我以为ValidateSet
属性可以满足您的目的,但是我意识到传统的param
块还不够.因此,我查找了DynamicParams
,这就是我发现的内容.这应该对您有用.
So you want Intellisense in your script. Ambitious move. Most people would settle for the file browser dialog box
. Anyway, I am going to have to refer you to smarter men than me. I was thinking ValidateSet
attribute would serve your purpose but I realized that the traditional param
block is not enough. So I looked up DynamicParams
and this is what I found. This should work for you.
https: //blogs.technet.microsoft.com/pstips/2014/06/09/dynamic-validateset-in-a-dynamic-parameter/
这篇关于在Import-Csv上选择文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!