Monthly Archive

Categories

Finding special folders

Windows has a number of special folders. These can be accessed either directly through the file system – for example the Documents special folder is C:\<user>\Richard\Documents or through code. But how do you go about finding special folders.

The easiest way is to use this script

1..1000 |
ForEach-Object {
$shell = New-Object -ComObject Shell.Application
$sf = $shell.NameSpace($psitem)

if ($sf) {

$props = [ordered]@{
Value = $psitem
Name = $sf.Title
Path = $sf.Self.Path
}

New-Object -TypeName PSobject -Property $props
}
}

Looping through the values 1-1000 the Shell.Application COM object is used to find the namespace corresponding to that number. If it exists, the value, name and path are output.

In the Path property you’ll either get a normal looking path e.g. C:\Windows\System32 or something like this - ::{645FF040-5081-101B-9F08-00AA002F954E} - which is the CLSID or Windows Class Identifier

Comments are closed.