Export to csv
Hello I use Exchange 2007 and run the below script on my mailbox server to generate a report. --> My question is how would I be able to export the result to a cvs file? I did tru to insert the Import-CSV C:\1.csv but I just do not manage to make it work... Can u please advise? # Get all the Mailbox servers and users count ForEach ($server in Get-MailboxServer) { # For each Mailbox server, get all the databases on it $strDB = Get-MailboxDatabase -Server $server # For each Database, get the information from it ForEach ($objItem in $strDB) { $intUsers = ($objitem | Get-Mailbox -ResultSize Unlimited).count # Get the size of the database file $edbfilepath = $objItem.edbfilepath $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2) $strDBsize = Get-ChildItem $path $ReturnedObj = New-Object PSObject $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity $ReturnedObj | Add-Member NoteProperty -Name "Size (GB)" -Value ("{0:n2}" -f ($strDBsize.Length/1048576KB)) $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($strDBsize.Length/1024KB)) $ReturnedObj | Add-Member NoteProperty -Name "User Count" -Value $intUsers Write-Output $ReturnedObj } } Thanks Graig
December 10th, 2010 11:44am

On Fri, 10 Dec 2010 16:40:53 +0000, Graiggoriz wrote: > > >Hello I use Exchange 2007 and run the below script on my mailbox server to generate a report. > >--> My question is how would I be able to export the result to a cvs file? I did tru to insert the Import-CSV C:\1.csv but I just do not manage to make it work... Can u please advise? [ snip ] # Get all the Mailbox servers and users count $info = @() # ADD THIS ########### ForEach ($server in Get-MailboxServer) { # For each Mailbox server, get all the databases on it $strDB = Get-MailboxDatabase -Server $server # For each Database, get the information from it ForEach ($objItem in $strDB) { $intUsers = ($objitem | Get-Mailbox -ResultSize Unlimited).count # Get the size of the database file $edbfilepath = $objItem.edbfilepath $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2) $strDBsize = Get-ChildItem $path $ReturnedObj = New-Object PSObject $ReturnedObj | Add-Member NoteProperty ` -Name "Server\StorageGroup\Database" -Value $objItem.Identity $ReturnedObj | Add-Member NoteProperty ` -Name "Size (GB)" ` -Value ("{0:n2}" -f ($strDBsize.Length/1048576KB)) $ReturnedObj | Add-Member NoteProperty ` -Name "Size (MB)" ` -Value ("{0:n2}" -f ($strDBsize.Length/1024KB)) $ReturnedObj | Add-Member NoteProperty ` -Name "User Count" -Value $intUsers #Write-Output $ReturnedObj # REPLACE THIS ##### $info += $ReturnedObj # WITH THIS ##### } } $info | export-csv ..... # ADD THIS ##### --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
December 10th, 2010 11:14pm

Thanks Rich it finaly works!! I have tried with another script I have and I followed your advice and could not manage to have the cvs file extracted: The script: Get-MessageTrackingLog -ResultSize Unlimited -Start "01/12/2010 00:00AM" -End "05/12/2010 11:59PM" |% { if ($domains -contains $_.sender.split("@")[1]){$sent[$_.sender.split("@")[1]] ++} $_.recipients |%{ if($domains -contains $_.split("@")[1]){$recv[$_.split("@")[1]] ++} } } $stats = @() $domains |% { $stat = ""|select DomainName,Inbound,Outbound $stat.DomainName = $_ $stat.Outbound = $sent["$_"] $stat.Inbound = $recv["$_"] $stats += $stat } $stats | ft -autosize I added at the en "$info | export-csv C:\mailflow.csv" but I get the below error message: Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null. At C:\scriptmailflow.ps1:27 char:19 + $info | export-csv <<<< "C:\mailflow.csv"
December 13th, 2010 2:54am

On Mon, 13 Dec 2010 07:50:26 +0000, Graiggoriz wrote: > > >Thanks Rich it finaly works!! > >I have tried with another script I have and I followed your advice and could not manage to have the cvs file extracted: > >The script: > >Get-MessageTrackingLog -ResultSize Unlimited -Start "01/12/2010 00:00AM" -End "05/12/2010 11:59PM" |% { if ($domains -contains $_.sender.split("@")[1]){$sent[$_.sender.split("@")[1]] ++} $_.recipients |%{ if($domains -contains $_.split("@")[1]){$recv[$_.split("@")[1]] ++} } } $stats = @() $domains |% { $stat = ""|select DomainName,Inbound,Outbound $stat.DomainName = $_ > >$stat.Outbound = $sent["$_"] $stat.Inbound = $recv["$_"] $stats += $stat } > >$stats | ft -autosize > >I added at the en "$info | export-csv C:\mailflow.csv" but I get the below error message: > >Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null. At C:\scriptmailflow.ps1:27 char:19 + $info | export-csv <<<< "C:\mailflow.csv" Well, that's not surprising. You haven't put anything into the "$info" variable! If you're looking to export what I think you are, use "$stats | export-csv . . . " --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
December 13th, 2010 10:32pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics