Converting the FileSystemObject's GetSpecialFolder Method
Definition: Depending on the parameter passed to it, this method returns a reference to the Windows folder, the System folder, or the Temp folder.
You can use the Get-Item cmdlet with the ENV: PowerShell drive to retrieve the environment variables to the Windows and Temp paths.
$a = Get-Item env:\windir
$a = Get-Item env:\temp
You can find the System folder by referencing the ComSpec environment variable, then using Split-Path with the -parent parameter to remove the file name:
$a = Get-Item env:\comspec $a = Split-Path $a.value -parent
Another option for retrieving the System folder, which is probably a little more straightforward, is to use WMI:
Here we’re using the Get-WMIObject cmdlet to retrieve a Win32_OperatingSystem object. One of the properties of Win32_OperatingSystem is SystemDirectory, which just happens to contain the full path to the System directory. And that’s exactly what we’re looking for.