Reputation: 131
I am having trouble with the following script. It seems to freakout with the spaces in the file path that I am checking for. Any ideas on how to not have the PoweShell freak out, with the Program Files (x86)
?
GC C:\server.txt | %{
$server = $_
if (Test-Path \\$server\c$\Program Files (x86)\some_dir\test.txt){
New-Object PSOBject -Property @{
Server = $server
Status = "Yes"
}
}else {
New-Object PSOBject -Property @{
Server = $server
Status = "No"
}
}
}| Export-Csv C:\temp\report.csv -nti
Upvotes: 2
Views: 14689
Reputation:
If your file path contains whitespace, you will need to use a string literal:
if (Test-Path "\\$server\c$\Program Files (x86)\some_dir\test.txt"){
Make sure you use double quotes though so that variables are properly expanded.
Upvotes: 4