How To Create File Selection Dialog Box in PowerShell

Поделиться
HTML-код
  • Опубликовано: 20 авг 2024
  • In this Video, you will learn how to enable file selection box in PowerShell to interactively select file while running script. Also, there are other parameter explained using some examples. You can use this script and let me know if you are facing any challenges.
    ==========================================================
    Add-Type -AssemblyName System.Windows.Forms
    $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
    If you want to redirect to specific folder
    ##InitialDirectory = "c:\Scripts\New Folder"
    If you want to user Environment Path like "Desktop/ My Documents"
    ##InitialDirectory = [Environment]::GetFolderPath('Desktop')
    If you want to add any Title to your Dialog Box
    Title = "Select Servers List"
    ##If you want to add file filter to your File Browser windows
    Filter = 'Select File |*.xlsx;*.txt'
    }
    $FileBrowser.ShowDialog()
    $File = $FileBrowser.Filename
    If( !$File )
    { Write-Warning "File not selected," }
    Else
    { $Servers = Get-Content -Path $File
    Write-Warning "File Selected" }
    ==========================================================
    Add User/Group To The Local Administrators/RDP Group On Multiple Computers
    • Add User/Group To The ...
    Get Windows Updates list from Remote Computer
    • Get Windows Updates li...
    PowerShell Remotely Uninstall Software from Multiple Computers
    • PowerShell Remotely Un...
    PowerShell Search Specific KB Status on Remote Computers
    • PowerShell Search Inst...
    PowerShell Script to Connect Multiple Server's Remote Session
    • PowerShell Script to C...
    PowerCLI Script to power ON dedicated VMs listed in a text file
    • PowerCLI Script to pow...
    PowerCLI Script to power Off dedicated VMs listed in a text file
    • PowerCLI Script to pow...
    Delete Snapshot's from Multiple Virtual Machines
    • Delete Snapshot's from...
    Create Snapshot on Multiple Virtual Machine
    • Create Snapshot on Mul...
    How can I check if a port is open remotely
    • Identify if Windows TC...
    Installing software remotely on Multiple "Workgroup" Computers
    • Installing software re...
    PowerShell Installing software remotely on Multiple Computers
    • PowerShell Installing ...
    Unable to move OU in Active Directory (Access is denied)
    • Unable to move OU in A...
    PowerShell Installing software remotely on Multiple Computers
    • PowerShell Installing ...
    Get Multiple Services Status Remotely | Remotely Start or Stop Services
    • Get Multiple Services ...
    Get Date and Time from Multiple Remote Computers
    • Get Date and Time from...
    PowerCLI - How to get HA restarted VM's List
    • PowerCLI - How to get ...
    Get-Childitem - Search file on Local and Remote Computers
    • Get-Childitem - Search...
    Remotely Create Update Delete Registry Key on Multiple Computers
    • Remotely Create Update...
    Get service status from remote server's using PowerShell
    • Get service status fro...

Комментарии • 3

  • @echy
    @echy Год назад

    why can folder name not show up in the file textbox

  • @Rasinzz
    @Rasinzz Год назад +1

    Is there anyway I can use this to select a folder rather than a file?

    • @SwapnilInfotech
      @SwapnilInfotech  Год назад

      Yes You can achieve that by using the below script which will open the Folder selection dialog box. But it will be different from the File selection dialog box. Please let me know if you have any questions. $out variable will have folder path in it.
      ===============================
      $FolderBrowser = new-object System.Windows.Forms.folderbrowserdialog;
      $out = $null;
      $caller = [System.Windows.Forms.NativeWindow]::new()
      $caller.AssignHandle([System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle)
      if (($FolderBrowser.ShowDialog($caller)) -eq [System.Windows.Forms.DialogResult]::OK.value__)
      {
      $out = $FolderBrowser.SelectedPath;
      }
      $out
      ===============================