简体   繁体   中英

I would like to open an file in powershell using the search from windows

I would like to open an file in powershell using the search from windows.

The problem is as followed I have an script that is:

1.reading out an .txt file
2.logs into an database
3. ads multiple rows in the tabel

This works like it should. Now comes the problem that the .txt file is found with an url that is hardcoded in the script:

$textfile= Get-Content C:\ODP.NET\test.txt

What I would like to do is that the user can open his own file using a simple search engine from windows. Take a look at the link below.

the link

good luck!

The answer

Function Get-FileName($initialDirectory)
{   
 [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
 Out-Null

 $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
 $OpenFileDialog.initialDirectory = $initialDirectory
 $OpenFileDialog.filter = "All files (*.*)| *.*"
 $OpenFileDialog.ShowDialog() | Out-Null
 $OpenFileDialog.filename
} #end function Get-FileName

Get-FileName -initialDirectory "c:\fso"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM