Tag Archives: PowerShell
How to script SharePoint Prerequisite IIS Role
When creating a new SharePoint 2013/2016/2019 server, the IIS web role needs to be installed with certain features enabled. Below is PowerShell one liner to accomplish that. Cheers. ![]()
Code
Add-WindowsFeature NET-HTTP-Activation,NET-Non-HTTP-Activ,NET-WCF-Pipe-Activation45,NET-WCF-HTTP-Activation45,Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Asp-Net45,Web-Net-Ext,Web-Net-Ext45,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation,Xps-Viewer -verbose
Screenshots
Delete ALL One-Time SPTimerJobs
One time SharePoint timer jobs can often get “stuck” and fail to execute. Clearing them all out manually in Central Admin is tedious. PowerShell below will remove all “One-time” jobs with a one liner. Cheers. ![]()
PowerShell Code
Get-SPTimerJob |? {$_.Schedule.GetType().ToString() -eq "Microsoft.SharePoint.SPOneTimeSchedule"} | % {$_.Delete()}Screenshot
References
Measure Performance – SharePoint Online (o365-speed)
PowerShell offers an excellent way to measure command line execution times with “Measure-Command” and Script Block. With the example below, we run 10 repetitions to connect to SharePoint online and measure the response time in milliseconds. Cheers! ![]()
Video
Measure Performance – SharePoint Online (o365-speed) from Jeff Jones on Vimeo.
Source Code
Screenshots
References
PWA Refresh – Clone Project Server to Lower Env (DEV)
Cloning a project server environment is not a simple procedure. Wanted to share notes to help others. Duplicating the SQL databases is a good start. However, there are internal issues with duplicate GUID (same number already in use) that can create issues.
To resolve that hurdle I coded PowerShell which generates a new GUID and updates Site Collection (SPSite) via TSQL directly. https://github.com/spjeff/spadmin/tree/master/SPContentDatabase-Replace-Site-GUIDs
With a fresh new GUID in place we can follow steps in SharePoint Central Admin, PowerShell, and PWA Settings to bring the new PWA database pairs (SharePoint Content + Project Plans) online for customers. Word DOC included below with step-by-step detail. Cheers! ![]()
Download Checklist
| PWA Refresh Procedure.DOC |
Diagram
References
- https://github.com/spjeff/spadmin/tree/master/SPContentDatabase-Replace-Site-GUIDs
- https://epmsource.com/2013/05/08/migrating-project-derver-2013-database-between-environments/
- https://docs.microsoft.com/en-us/project/deploy-project-web-app-with-a-new-site-collection-project-server-2013
- https://docs.microsoft.com/en-us/powershell/module/sharepoint-server/mount-spcontentdatabase
- https://docs.microsoft.com/en-us/powershell/module/sharepoint-server/set-spprojectpermissionmode?view=sharepoint-ps
FIXED – Cannot convert the JSON string … contains the duplicated keys ‘Id’ and ‘ID’
Recently I came across the error message below when download a SharePoint 2013 List item REST api call to PowerShell. The cmdlet ConvertFrom-JSON does an excellent job. However, it is case sensitive with property names.
The resolution I found was to first string replace (case sensitive) to rename one of the source property names. Cheers! ![]()
Screenshot – Before
ConvertFrom-Json : Cannot convert the JSON string because a dictionary that was converted from the string contains the duplicated keys ‘Id’ and ‘ID’.
Screenshot – After
Code
cls
# Config
$web = "http://portal/sites/team"
$list = "Test"
# Digest
$urlView = "$web/_api/contextinfo"
$urlView
$req = Invoke-WebRequest $urlView -UseDefaultCredentials -UseBasicParsing -Method Post
$ctx = $req.Content
$digest = $ctx.GetContextWebInformation.FormDigestValue
$digest
# List Items
$urlItems = "$web/_api/web/lists/GetByTitle('$list')/getitems"
$json = "application/json; odata=verbose"
$headers = @{"Accept" = $json; "Content-Type" = $json; "X-RequestDigest" = $digest}
$body = '{"query":{}}'
$req = Invoke-WebRequest $urlItems -UseDefaultCredentials -UseBasicParsing -Method Post -Body $body -Headers $headers
$resp = $req.Content
### FIX - Case Sensitive Property Name Replacement ###
$resp = $resp.Replace("Id","Idd")
$json = $resp | ConvertFrom-Json
$jsonReferences
FIXED – stsadm upgrade command has been replaced by psconfig.exe
Recently I came across the error below when upgrading a SharePoint 2016 farm. Expected product behavior and simply a case of training SharePoint Administrators to use PSCONFIG.EXE command line instead. Cheers! ![]()
Error Screenshot
stsadm -o upgrade -inplace b2b –force Command line error. Invalid parameter. stsadm –o upgrade command has been replaced by psconfig.exe -cmd upgrade
New Command
PSCONFIG -cmd upgrade -inplace b2b -wait -cmd applicationcontent -install -cmd installfeatures -cmd secureresources -cmd services -install
References
VIDEO – PowerShell automated WebDeploy ZIP install
This video will demonstrate how to test, build, publish, and install WebDeploy ZIP packages. The example walks through a simple WebAPI HTTP endpoint which echoes back the current date and time. Fiddler is leveraged for HTTP testing. Once tested succesful, we publish the project to ZIP for install on IIS hosted infrastructure.
PowerShell cmdlet Restore-WDPackage is used to extract ZIP content and create a permanent home for the API endpoint.
By automating with PowerShell we provide a fast consistent admin experience to ensure the API is always installed the same way for a reliable repeatable procedure. Thanks for watching.
Video
Code
Add-PSSnapin WDeploySnapin3.0
$package = "C:\temp\Hello\deploy\Hello.zip"
Restore-WDPackage $package -Parameters @{"IIS Web Application Name"="API/Hello"}Screenshot
References
PowerShell – Install Module (Verbose Debug)
By setting the system variable $debugPreference = “Continue” we are able to see file level detail when installing PowerShell modules. This can be helpful to gain an understanding of the dependency and files contained with a module. Cool trick I didn’t know about until today.
Code
$debugPreference = "Continue"
Install-Module SharePointPNPPowerShell2013 -Scope CurrentUser -AllowClobber
Get-Command |? {$_.Source -like '*SharePointPNP*'} | ftScreenshots
Reduce SPPKG WebParts Features with Powershell
The below steps will reduce a SPPKG to only select Features and WebParts we want to keep. Every SPPKG file is actually a ZIP with XML manifest and subfolder for each WebPart and Feature. Extracting the SPPKG as ZIP allows us to review the internal content, enumerate all Features, and then select ones to keep in a final compressed ZIP file (SPPKG file).
If you want to upload only a few WebParts from a SPPKG package to Office 365’s App Catalog then check out the video below.
Video
Code
Screenshots
References
VIDEO – Populate Word DOCX with PowerShell
Recently I found a way to dynamically update Microsoft Word text placeholders with PowerShell script. Because DOCX files are ZIP archive we can extract to a TEMP folder to update the internal XML document text. From there, bundling to a new ZIP archive and renaming DOCX enable us to deliver the final DOCX version to users.
Below is a demo with full source code. Cheers! ![]()
