Create PowerShell Code in Excel B
String - Array - ForEach Loop
A PowerShell with SharePoint tutorial
When
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.
When
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.
|