Example content

$file = ".\example.txt"
$tool = "$env:SystemRoot\System32\notepad.exe"

Open current folder

Invoke-Item -Path .
explorer (Resolve-Path .) # can only open one folder
  • abbreviate ii .

Reveal one file or folder

explorer "/select,`"$(Resolve-Path $file)`""

Copy using Windows Explorer UI

  • from $source to $destination with $copyFlags
$objShell = New-Object -ComObject 'Shell.Application'    
$objFolder = $objShell.NameSpace((Resolve-Path $destination).Path)
$objFolder.CopyHere((Resolve-Path $source).Path, $copyFlags)

The $copyFlags are a bitwise combination of the following vOptions flags:

  • 0x0004 : no UI, Do not display a progress dialog box.
  • 0x0008 : rename duplicates, Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.
  • 0x0010 : yes to all, Respond with “Yes to All” for any dialog box that is displayed.
  • 0x0040 : allow undo, Preserve undo information, if possible.
  • 0x0080 : require wildcard, Perform the operation on files only if a wildcard file name like *.* is specified.
  • 0x0100 : UI without filenames, Display a progress dialog box but do not show the file names.
  • 0x0200 : create directories, Do not confirm the creation of a new directory if the operation requires one to be created.
  • 0x0400 : no error UI, Do not display a user interface if an error occurs.
  • 0x0800 : no security attributes, Do not copy the security attributes of the file. (Version 4.71.)
  • 0x1000 : no recursion, Only operate in the local directory. Do not operate recursively into subdirectories.
  • 0x2000 : no file grouping, Do not copy connected files as a group. Only copy the specified files. (Version 5.0.)
ValueSummaryDescription
0x0004
= 4
no UIDo not display a progress dialog box.
0x0008
= 8
rename duplicatesGive the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.
0x0010
= 16
yes to allRespond with “Yes to All” for any dialog box that is displayed.
0x0040
= 64
allow undoPreserve undo information, if possible.
0x0080
= 128
require wildcardPerform the operation on files only if a wildcard file name like *.* is specified.
0x0100
= 256
UI without filenamesDisplay a progress dialog box but do not show the file names.
0x0200
= 512
create directoriesDo not confirm the creation of a new directory if the operation requires one to be created.
0x0400
= 1024
no error UIDo not display a user interface if an error occurs.
0x0800
= 2048
no security attributesDo not copy the security attributes of the file. (Version 4.71.)
0x1000
= 4096
no recursionOnly operate in the local directory. Do not operate recursively into subdirectories.
0x2000
= 8192
no file groupingDo not copy connected files as a group. Only copy the specified files. (Version 5.0.)

Example: combine create directories, no error UI and rename duplicates

$copyFlags = 0x400 + 0x200 + 0x8
$copyFlags = 0x608

Sources:

Related:

Tags:
File System - Use paths, get meta data, link, download, and encrypt files and folders