0

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.

1 Answer 1

2

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

$location = Get-FileName
copy $location c:\temp
start $location
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.