Converting the FileSystemObject's IsRootFolder Property

Definition: Returns True if the specified folder is the root folder.


We don’t know of a similar property in PowerShell or the .NET Framework, but you can find the root of a folder, and if that root is equal to the folder, then the folder is the root. Something like this:

$folder = "C:\"
$a = New-Object -typename System.IO.DirectoryInfo $folder
if ($folder -eq $
    "$folder is a root folder."
    "The root of $folder is " + $

We start by setting the variable $folder to the folder we want to check. We then use the New-Object cmdlet to retrieve a reference to the DirectoryInfo of that folder. At that point we can check the Name property of the Root for that folder. If the name of the root is the same as the folder, then the folder is the root. Otherwise we display the name of the root for that folder.

See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page