Home >Tips >PowerShell with SharePoint from Scratch >Create PowerShell Code in Excel B kalmstrom.com site map icon Site map  

Create PowerShell Code in Excel B

String - Array - ForEach Loop

A PowerShell with SharePoint tutorial

PowerShell iconWhen you have an Excel list with words that can be used as SharePoint app names, you can use it to quickly create code for PowerShell.

In the previous article, we saw how an Excel list with department names can be used to create multiple function calls, that can be run in PowerShell to create multiple SharePoint apps.

Another way to create code in Excel from the same list of department names, is to join the departments in a string. Then we will use the string to create a PowerShell array.

$Departments = 'HR','Marketing','IT','Sales','Engineering'

The array will be used in a forEach loop that runs the PowerShell function and creates SharePoint lists. Note that the Excel list must formatted as a table in both this and the previous examples.

foreach($Dep in $Departments){
    Create-MyList -ListName $Dep -ListURL $Dep
}

In the demo below, Peter Kalmström shows how to create the string in Excel and build the array and forEach loop in PowerShell.

PowerShell with SharePoint from Scratch coverWhen he has run the function with the forEach loop and made sure that the SharePoint apps have been created, he finally uses PowerShell to remove all the apps from SharePoint again.


You will find more detailed explanations in the book.


back icon next icon
Products Buy FAQ Services Tips Books Contact About Us Tools

Security and integrity

Copyright  Kalmstrom Enterprises AB  All rights reserved