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 $server.name -quiet -count 1) {

write-host “-------------”;
write-host $server.name;
write-host “-------------”;

$shares = gwmi win32_share -computer $server.name;

foreach ($share in $shares) {

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

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

}

write-host “”;

}
}

https://social.technet.microsoft.com/Forums/en-US/dceb9696-0f92-4d3c-a94e-febb9da54e12/need-to-add-importcsv-command?forum=ITCG

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.