문제

I've been trying to figure this out for a while, but no luck, I would like to pop up a file open dialog, which I have been able to do with a function I found online, and then use the file location further down the line in my script, but I can't figure it out.

Here is the function

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

 $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
 $OpenFileDialog.initialDirectory = "C:\Users\$($env:username)\Documents\"
 $OpenFileDialog.filter = "CSV's (*.csv)| *.csv"
 $OpenFileDialog.ShowDialog() | Out-Null
 $OpenFileDialog.filename
}

I'm new to powershell so I'm not sure how functions work.

도움이 되었습니까?

해결책

Keep it in a variable and use it whenever you like.

$location = Get-FileName
copy $location c:\temp
start $location
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top