get a folder path from the explorer menu to a powershell variable

后端 未结 5 834
忘掉有多难
忘掉有多难 2021-01-19 04:42

is it possible to open a explorer window from powershell and store the path selected in the explorer, to a variable?

to open explorer window from powershell

5条回答
  •  再見小時候
    2021-01-19 05:26

    The above did not work for me. Running Windows 7 with Powershell Version 2. I did find the following, which did allow the pop-up and selection:

        Function Select-FolderDialog
        {
             param([string]$Description="Select Folder",[string]$RootFolder="Desktop")
    
         [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") Out-Null     
    
         $objForm = New-Object System.Windows.Forms.FolderBrowserDialog
         $objForm.Rootfolder = $RootFolder
         $objForm.Description = $Description
         $Show = $objForm.ShowDialog()
         If ($Show -eq "OK")
         {
             Return $objForm.SelectedPath
         }
         Else
         {
            Write-Error "Operation cancelled by user."
         }
        }
    

    Just in case others have the same issues.

提交回复
热议问题