PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,595 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
$servers = Get-Content -path C:\temp\fileshares.txt
foreach ($server in $servers) {
Write-Host "Getting file shares from $server..."
$fileshare = Get-WmiObject -Class Win32_Share -ComputerName $server |
Where-Object {$_.Name -like "*$"} |
Select-Object @{n="Server";e={$server}}, Name, Path, @{n="Owner";e={(Get-Acl $_.Path).Owner}}
$fileshare | out-file C:\temp\result.csv -Append
}
output is showing in single column in excel and also column names is showing for every server. please help to get column names only once and data for all servers
Hi,
You can store all the results in one array.
$servers = Get-Content -path C:\temp\fileshares.txt
$fileshare = @()
foreach ($server in $servers) {
Write-Host "Getting file shares from $server..."
$fileshare += Get-WmiObject -Class Win32_Share -ComputerName $server |
Where-Object {$_.Name -like "*$"} |
Select-Object @{n="Server";e={$server}}, Name, Path, @{n="Owner";e={(Get-Acl $_.Path).Owner}}
}
$fileshare | out-file C:\temp\result.csv
Best Regards,
Ian Xue
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more
Double post