Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell: Export-Csv gives only one result

Posted on 2014-03-31
3
Medium Priority
?
872 Views
Last Modified: 2014-03-31
Hi,

I have this script that shows the shares that are published bij DFS.
I want to pipe the output to a csv file. There are more than 40 shares in DFS, but the script places only one result into the csv.
Only if I add an "-append"at the of the Export-Csv line, I get all the results.
The problem to that is, the csv is not overwritten.
Can someone help me on this ?

Clear-Host
$search= "department"
$dfsroots=Get-DfsnRoot
foreach ($root in $dfsroots) {
write-Host $root.NameSpacePath
$check=Get-DfsnFolder -Path "$($root.NamespacePath)\*" | Get-DfsnFolderTarget | Select-String $search foreach ($path in $check) {
$path=$path.ToString().Replace('?','$') -split "="
$path=$path.Split(',')
$shares=$path[3].Replace(')','')
#Out-File -filepath "C:\Temp\Shares.txt" -InputObject "$shares"
""|select-object @{Name="Shares";Expression={$shares}}|Export-Csv C:\Temp\shares.csv -NoTypeInformation -append 
}
}

Open in new window

0
Comment
Question by:Loyall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 39966640
The script behaves exactly as it should.
In the loop you get exactly one share, and you export that to the shares.csv file.

If you want to clear the file, just put this at the top:
Clear-Content C:\Temp\shares.csv

Open in new window

HTH,
Dan
0
 
LVL 2

Author Closing Comment

by:Loyall
ID: 39968500
Thanks a lot, Dan !
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39968550
Glad I could help!
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question