Converting the FileSystemObject's GetExtensionName Method

Definition: Given a file name or full path, returns the file extension of the file (without the .).


In PowerShell, you can use the Get-Item cmdlet to retrieve a reference to the file, then check the Extension property:

$a = Get-Item c:\scripts\test.txt

You can also do this in one line:

(Get-Item c:\scripts\test.txt).extension

Note that, unlike GetExtensionName, the Extension property includes the dot in the name. In other words, the preceding command will return .txt, not simply txt.

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