Import-csv command piping needs to be done in below code

Please help me to ad Import-csv in below code. Below code is for used to get computer from AD and then find the shared folder path from it.

What my requirement is I will provide the input file of computer name by using Import-csv command and then will fetch the shared folders present on each server or computer.



import-module activedirectory;

$servers = get-adcomputer “Hostname” | where {$_.enabled -eq $true};

foreach ($server in $servers) {

if(test-connection -cn $ -quiet -count 1) {

write-host “-------------”;
write-host $;
write-host “-------------”;

$shares = gwmi win32_share -computer $;

foreach ($share in $shares) {

if (($ -ne “print$”) -and ($share.path -notlike “LocalsplOnly”) -and ($ -notmatch “.$”) -and ($ -ne “ipc$”) -and ($ -ne “sysvol”) -and ($ -ne “netlogon”)-and ($ -ne “admin$”)) {

$out = $ + “,” + $ + “,” + $share.path;
$out >> c:\output.csv


write-host “”;


You should explain more detailed what exactly you’re trying to do. I’d recommend to ask the author of the script for assistance.

When you post code please format it as code using the code tag button right above the edit box of the post editor. Thanks
You can edit your already existing post - you don’t have t o create a new one.