I am creating a csv flat with some data. One of the column is content type which may have one or more content types in the column (string values). How do I include all the values from the array object into the flat file but with the respected row? See the code below... I passed $ct to the add-content but flat file does not have the content type data in it. when I do write-host for $ct I see that it has values. Please suggest.
#For Output file generation
$OutputFN = "Libraries.csv"
#delete the file, If already exist!
if (Test-Path $OutputFN)
{
Remove-Item $OutputFN
}
#Write the CSV Headers
Add-Content $OutputFN "Web URL, Site Name, Library Name, Content Types"
$systemlibs =@("Converted Forms", "Customized Reports", "Documents", "Form Templates",
"Images", "List Template Gallery", "Master Page Gallery", "Pages",
"Reporting Templates", "Site Assets", "Site Collection Documents",
"Site Collection Images", "Site Pages", "Solution Gallery",
"Style Library", "Theme Gallery", "Web Part Gallery", "wfpub")
#Get the Site collection
$Site= Get-SPSite "http://inside.contoso.com"
$spWebApp = $Site.WebApplication
foreach($allSites in $spWebApp.Sites)
{
#Loop through all Sub Sites
foreach($Web in $allSites.AllWebs)
{
#Write-Host "-----------------------------------------------------"
#Write-Host "Site Name: '$($web.Title)' at $($web.URL)"
#Write-Host "-----------------------------------------------------"
foreach($list in $Web.Lists)
{
if($list.BaseTemplate -eq "DocumentLibrary" -and $list.AllowContentTypes -eq $true)
{
if(-not ($systemlibs -Contains $list.Title))
{
if ($list.AllowContentTypes -eq $true)
{
$ct = @()
foreach ($contenttype in $list.ContentTypes)
{
$ctProperties = @{ContentType = $contenttype.Name}
$ctObject = New-Object PSObject -Property $ctProperties
#write-host $ct
$ct += $ctObject
#write-host $ct
#Write-Host "$($web.URL), $($web.Title), $($list.Title), $ct"
}
#$ct
write-host $ct
#Write-Host "$($web.URL), $($web.Title), $($list.Title), $($ct)"
$content = $web.URL + "," + $web.Title +"," + $list.Title +"," + $ct
add-content $OutputFN $content
}
}
}
}
}
}