Adding images with PnP/Powershell
July 28, 2017 by Corrie Haffly

Oh, hello! Welcome back to our guest blogger series. This is your chance to learn a little something about the men and women behind the screen and discover what drives them.

Today we welcome back our Senior Web Developer Corrie Haffly for another trip into the world of Powershell and PnP. When we last left off, we learned how to build a basic site provisioning package and deploy it. But where else can we go? Enjoy part 2 of our look into Powershell and PnP.

Provision the site and see your changes.

If you are continuing on from the previous tutorial, you can skip to step 4.

Open Windows Powershell as an admin (right-click on Powershell and choose Run as administrator).

CD to the folder that contains simple.ps1:cd: "C:\yourdirectory"

Add in your credentials.

$creds = Get-Credential

Enter your credentials.

Run the simple.ps1 file (with the URL to your own site, of course):.\simple.ps1 -TargetWebUrl "https://yoursite.com/sites/sitecollection" -Credentials $creds

Wait. You will see a bar across the top which shows the progress of the deployment. This may take a few minutes, so grab a snack.

When it is complete, go to your site in the browser, go to the Images folder, and you’ll see that the images have been added to your site!

Additional notes

You can re-provision your site as many times as you want. Adding files with PnP will rewrite the existing version of the file that is already up, so if, for example, you want to replace the computer.jpg image with an updated version, you can replace the computer.jpg image in your folder structure with a new version, and then redeploy the script. PnP/Powershell will push the new version of the image up to the site.

PnP/Powershell provides a way to easily reproduce site structures across site collections. You can easily deploy this to a different site collection, as many times as you want, and it will do the same thing every time. As you think about how PnP/Powershell can deploy content types, list structure, page layouts, and more, you can appreciate even more the powerful site templates that you can create with a PnP/Powershell solution.