Using this:
$site = Get-SPSite "http://contoso.comsites/Todd"
I am able to get this:
Title
-----
Todd
I want to just take the "Todd" and use it in the filename when outputting to CSV.
This is my script:
#Add the SharePoint Powershell SnapIn
Add-PSSnapin microsoft.sharepoint.powershell -EA 0
#Edit the URL below for the specific site collection you wish to extract alerts from
$site = Get-SPSite "contoso.rjf.com/.../Todd"
$TitleString = Get-SPSite $site | Get-SPWeb -Limit All | Select Title
$alertResultsCollection = @()
foreach ($web in $site.AllWebs) {
foreach ($alert in $web.Alerts){
$alertURL = $web.URL + "/" + $alert.ListUrl
$alertResult = New-Object PSObject
$alertResult | Add-Member -type NoteProperty -name "List URL" -value $alertURL
$alertResult | Add-Member -type NoteProperty -name "Alert Title" -value $alert.Title
$alertResult | Add-Member -type NoteProperty -name "Alert Type" -value $alert.AlertType
$alertResult | Add-Member -type NoteProperty -name "Subscribed User" -value $alert.User
$alertResultsCollection += $alertResult
}
$site.Dispose()
$alertResultsCollection
$Path = "F:\"
$Prefix = $TitleString
$Suffix = "_SiteAlerts"
$FileExt = ".csv"
## Export to CSV
$alertResultsCollection | Export-CSV ($path + $Prefix + $Suffix + $FileExt)
What this does is give me a filename as "@{Title=Todd}_SiteAlerts.csv"
How do I get it to just give me Todd_SiteAlerts.csv?PS.....not a big fan of the $path + $Prefix + $Suffx + $FileExt either.
Thanks so much Tim! Worked like a charm. Believe it or not, I didn't need the [string]. What truly worked was adding the -expandproperty.
SWEEEEET. Thanks.