Wednesday, August 06, 2008
#
So you want to determine if a folder or file exists with PowerShell? You can invoke the same scripting object you might remember from VB....
#set a var for the folder you are looking for
$folderPath = 'C:\Temp\'
#instantiate the FileSystemObject
$objFSO = New-Object -ComObject Scripting.FileSystemObject
#check to see if it is missing
if($objFSO.FileExists($folderPath -eq $FALSE))
{
echo "The folder does not exist."
exit
}
else
{
echo "The folder exists."
exit
}