Link to home
Start Free TrialLog in
Avatar of Kasper Katzmann
Kasper KatzmannFlag for Denmark

asked on

appending content to existing csv file

I have a lot of rooms in our Exchange 2010 setup and I have been asked to produce a list with all rooms and the persons that are ResourceDelegates and are listed in BookinPolicy. I have come this far, but the problem is, that I only have Powershell V2 and -append is a V3 feature.

$rooms = Get-Mailbox -RecipientTypeDetails RoomMailbox

ForEach ($room in $rooms) {

$mRoom = $room.name

$rows = Import-Csv c:\tools\bookingplan\bookingplan.csv

$cont = Get-CalendarProcessing $mRoom | `
		Select Identity, `
		@{Name=’Bookinpolicy’;Expression={[string]::join(";", ($_.BookInPolicy))}}, `
		@{Name=’ResourceDelegates’;Expression={[string]::join(";", ($_.ResourceDelegates))}} | `
			Export-Csv -append -path c:\tools\bookingplan\bookingplan.csv -Encoding Unicode
}

Open in new window

How do I get the output then?
Avatar of becraig
becraig
Flag of United States of America image

Move the export-csv to outside the for-each loop.
Create a second file and concatenate.
Avatar of Kasper Katzmann

ASKER

Moving the Export-Csv part outside the foreach loop will only take the last loop.
I have tried to concatenate but I seem to fail on that part. Can you be more specific? Example (please)?
$rooms = Get-Mailbox -RecipientTypeDetails RoomMailbox

ForEach ($room in $rooms) {

$mRoom = $room.name

$rows = Import-Csv c:\tools\bookingplan\bookingplan.csv

$cont += Get-CalendarProcessing $mRoom | `
		Select Identity, `
		@{Name=’Bookinpolicy’;Expression={[string]::join(";", ($_.BookInPolicy))}}, `
		@{Name=’ResourceDelegates’;Expression={[string]::join(";", ($_.ResourceDelegates))}} 
} $cont | Select * | Export-Csv -append -path c:\tools\bookingplan\bookingplan.csv -Encoding Unicode

Open in new window




See if this works for you.
ASKER CERTIFIED SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looking at the script above, you are writing back to the same file you are reading from ?

$rows = Import-Csv c:\tools\bookingplan\bookingplan.csv

Export-Csv -path c:\tools\bookingplan\bookingplan.csv

I might make sense for the moment to just write to another file so you do not lose your source (as you resolve this)  ?
You are my new best friend :-)
It works like intended and I am happy. Thank you very much.

/Kasper
Avatar of ncfbins
ncfbins

I know this is old, but its exactly what I am looking for. I am having issues running this script. It doesnt seem to create the CSV file before it tries to append to it.