Testing network path with powershell

Testing network path with powershell

If you want to scan a large list of network path to suppress old references, here is how to do it quickly in powershell.

Beware : if you don’t have authorization on the share the result will be the same as if it doesn’t exist

 

#Network path test
foreach ( $path_to_check in ( Get-Content ./list_path.txt)) {
echo “Scanning -> $path_to_checkif (Test-Path $path_to_check) {
	echo "$path_to_check,yes" >> ./check_path_restult.csv
	}
else {
	echo "$path_to_check,no" >> ./check_path_restult.csv
	}
}

 

 

Example :

 

PS D:\tmp> foreach ( $path_to_check in ( Get-Content ./list_path.txt)) {
>> echo "Scanning -> $path_to_check"
>> if (Test-Path $path_to_check) {
>>     echo "$path_to_check,yes" >> ./check_path_restult.csv
>>     }
>> else {
>>     echo "$path_to_check,no" >> ./check_path_restult.csv
>>     }
>> }
>>
Scanning -> \\host000001\bibli
Scanning -> \\host000001\dom101$
Scanning -> \\host000001\dom33
Scanning -> \\host000001\dom38

 

Content of result file (check_path_restult.csv) :

 

\\host000001\bibli,yes
\\host000001\bibli,yes
\\host000001\dom101$,yes
\\host000001\dom33,no
\\host000001\dom38,yes

Leave Comment

Your email address will not be published. Required fields are marked *