Useful SharePoint PowerShell Snippets


SharePoint Update


```PowerShell

if($env:USERNAME -notlike "*spfarm*"){
    Write-Warning "Please, execute the script as SPFarm account";
    return -1;
}

$thisFile = (Get-Item $PSCommandPath);

$logsFolder = "$($thisFile.Directory.Parent.FullName)\Logs";
New-Item $logsFolder -ErrorAction Ignore;

Start-Transcript "$($logsFolder)\$(Get-Date -Format 'yyyy-MMdd-HHmm')-$($thisFile.BaseName)-$($env:COMPUTERNAME).log" -IncludeInvocationHeader;

try {

    try{

        Add-PSSnapin Microsoft.SharePoint.PowerShell;

        Write-Host "`r`n`r`nUpgrading content databases`r`n`r`n" -ForegroundColor Yellow;

        foreach($db in (Get-SPContentDatabase)){
            Write-Host "Upgrading DB: $($db)";
            Upgrade-SPContentDatabase $db -Confirm:$false -ErrorAction Continue;
        }

    } catch {
        $Error | % { Write-Error $_; };
        $Error.Clear();
    }

    #Install-SPApplicationContent -Verbose;
    #Install-SPFeature -AllExistingFeatures -Verbose;

    Write-Host "`r`n`r`nExecuting PSCONFIG`r`n`r`n" -ForegroundColor Yellow;

    PSCONFIG.EXE -cmd upgrade -inplace b2b -force -cmd applicationcontent -install -cmd installfeatures;
    #PSConfig.exe -cmd upgrade -inplace b2b -wait -cmd applicationcontent -install -cmd installfeatures -cmd secureresources -cmd services -install;

} finally {
    Stop-Transcript;
}

```

Comments

Popular posts from this blog

SharePoint PnP Management Shell - Permissions Consent