#############################################
# Title: SiteCollection_Primary & secondayOwner.ps1
# Created By : Suresh Kumar Durairaj
#############################################
#region Addins
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Publishing")
[System.Reflection.Assembly]::LoadWithPartialName("System")
[System.Reflection.Assembly]::LoadWithPartialName("System.IO")
[System.Enum]::GetNames("Microsoft.SharePoint.SPBasePermissions")
#endregion
#region Log
$fileName = "Primary_Secondary_sitecollectionOwner"
$logdatetime=Get-Date -Format "MM-dd-yyyy_hh-mm-ss"
$logFileName = $fileName +"_" +$logdatetime+ "_Log.txt"
$invocation = (Get-Variable MyInvocation).Value
$directoryPath = Split-Path $invocation.MyCommand.Path
$logPath = $directoryPath + "\" + $logFileName
$CSVPath= $directoryPath + "\" +$fileName +"_" +$logdatetime+".csv"
$isLogFileCreated = $False
function Write-Log([string]$logMsg)
{
if(!$isLogFileCreated){
Write-Host "Creating Log File..."
if(!(Test-Path -path $directoryPath))
{
Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}
else
{
$script:isLogFileCreated = $True
Write-Host "Log File ($logFileName) Created..."
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}
else
{
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}
#endregion
# Declare an array to collect our result objects
$resultsarray =@()
Get-SPSite -Limit All | Select Url, Owner, SecondaryContact| Export-csv $CSVPath -notypeinformation
#region Remove addins
Remove-PsSnapin Microsoft.SharePoint.PowerShell
#endregion
No comments:
Post a Comment