SharePoint PowerShell - JackHu88/Comm GitHub Wiki

Test-SPContentDatabase -name sharepoint_content_5600 -webapplication http://sp2013:2019/  
Get-SPContentDatabase -webapplication   http://sp2013:2025
Get-SPContentDatabase    5a0b958b-81e5-4ea8-b9b8-47826a95e518| Remove-SPContentDatabase 
Mount-SPContentDatabase "Sharepoint_Content_6100" -DatabaseServer "cnqamossdb01" -WebApplication http://sp2013/ 
Convert-SPWebApplication -Identity http://sp2013/    -From Legacy  -To Claims -RetainPermissions -Force 
Upgrade-SPSite http://sp2013-VersionUpgrade

1)Set-SPLogLevel –TraceSeverity VerboseEx

2)New-SPLogFile

3)New-SPLogFile

4)Get-SPDiagnosticConfig | select LogLocation

5)Clear-SPLogLevel



Add-SPSolution  -LiteralPath  D:\Jack\RebatePayment.wsp
如果只想在当前服务器部署,那么请在部署命令后面加参数Local
Update-SPSolution -Identity MMAWebPart.wsp -LiteralPath "D:\Jack\MMAWebPart.wsp" -GACDeployment -Force -Local
Remove-SPSolution -Identity  rebatepayment.wsp    -Force


Install-SPSolution -identity rebatepayment.wsp -webapplication http://sp2013:3333 -GACDeployment -Force

Install-SPSolution -identity RebatePayment.wsp -webapplication http://sp2013:3333 -gacdeployment -CompatibilityLevel 15 -force -local


upgrade-spcontentdatabase -Id  c5c99ff8-7d86-40a2-a94b-0e805e93977b


Restore-SPSite  -Identity http://sp2013:5000/Site/ -Path "D:\Jack\Site.bak" -Force 
New-SPWeb http://sp2013:2021/sites/IT -Template "STS#1"
Get-SPSite http://sp2013 | Get-SPWeb -Limit ALL |%{ Get-SPFeature -Web $_ } | Select DisplayName,ID -Unique


Export-SPWeb http://sp2013/ESPE  -Path "C:\cmp\ESPE.cmp"  -IncludeUserSecurity   -Verbose
Import-SPWeb http://sp2013:2021/sites/test -Path  "C:\cmp\test.cmp" -IncludeUserSecurity  -Force -Verbose

Export-SPWeb -Identity  http://sp2013:2020   -Path "C:\cmp\web2020List.cmp" -ItemUrl /TeamSite/Shared%20Documents  -IncludeUserSecurity  -Verbose

Export-SPWeb -Identity <SiteURL> -Path <Path and File Name> [-ItemUrl <URL of Site, List, or Library>] [-IncludeUserSecurity] [-IncludeVersions] [-NoFileCompression] [-GradualDelete] [-Verbose]

Export-SPWeb -Identity http://sp2013:2022 -ItemUrl  /OGC/Lists/Orders -Path "C:\cmp\Orders.cmp"    -IncludeUserSecurity  -Verbose

Export-SPWeb -Identity http://sp2013:7777 -ItemUrl /Lists/ScanAsset -Path "D:\Jack\ScanAsset.cmp" -IncludeVersions All 


//create a new content database
New-SPContentDatabase "<database name>" -DatabaseServer "<database server / alias>" -WebApplication http://sitename
//move a site collection to the new content database
Move-SPSite http://webapp/sites/sitename -DestinationDatabase ContentDb2



Not able to open a SharePoint modern site using SharePoint Designer

$cred = Get-Credential
Connect-SPOService -Url https://TENANTNAME-admin.sharepoint.com -credential $cred
Set-SPOSite -Identity https://TENANTNAME.sharepoint.com/sites/SITENAME -DenyAddAndCustomizePages $false
 
# to test if it changed
$site = Get-SPOSite -Identity https://firemountain.sharepoint.com/sites/Office365Training
$site.DenyAddAndCustomizePages
Disconnect-SPOService

Update user profile for user whose account name has changed in AD

Get-SPUser "i:0#.w|domain\account" -web "http://sp2013/sites/it"	
Set-SPUser "i:0#.w|domain\account"  -SyncFromAD -web "http://sp2013/sites/it"

User changed domain

Step 1: Move-SPUser –ignoresid

# Get the user
$user = Get-SPUser -Identity "i:0#.w|DomainA\JaneDoe" -Web http://webUrl
# Write new alias to the content database
Move-SPUser -Identity $user -NewAlias "i:0#.W|DomainB\JaneDoe" -IgnoreSid

Step 2: Set-SPUser with SyncFromAD

# get the moved user
$newuser = Get-SPUser -Identity "i:0#.w|DomainB\JaneDoe" -Web http://webUrl
# sync move user from AD
Set-SPUser -Identity $newuser -SyncFromAD -Confirm:$false

https://n8d.at/move-users-from-domain-a-to-domain-b-in-sharepoint-with-claims-authentication-enabled/

https://gallery.technet.microsoft.com/office/Migrating-bulk-SharePoint-72863e36

Replace an expiring client secret in a SharePoint Add-in

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/replace-an-expiring-client-secret-in-a-sharepoint-add-in

PNP PowerShell

//get start https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/connect-sharepoint-online?view=sharepoint-ps

//Install sharepoint online management shell https://www.microsoft.com/en-us/download/details.aspx?id=35588

Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version

//install pnp powershell https://github.com/pnp/PnP-PowerShell

//work $targeturl = "https://skydrive3m.sharepoint.com/sites/gccn/" Connect-PnPOnline -Url $targetUrl -UseWebLogin

From https://github.com/pnp/PnP-PowerShell/issues/2949

⚠️ **GitHub.com Fallback** ⚠️