Introduction
Hi guys, let's explore a smart way to call another Power Shell script inside a script.
Let my given script be a test.ps1 which only does some write-host that prints some statement.
Now I'm adding one more line that calls a PowerShell script to execute.
Write-Host "Hello World!";
Write-Host "Invoking or Calling another PnP PS Script";
Powershell .\CreateFolder_PnP

The above CreateFolder_PnP script is shown below:
- #Config Variables
- $SharePointSiteURL = "#######################"
- $FolderName = "Extra Folderss"
- $RelativeURL = "/Reports Archive"
- #Relative URL of the Parent Folder
- Try {
- #Connect to PnP Online
- # Connect - PnPOnline - Url $SharePointSiteURL - CurrentCredentials
- Connect - PnPOnline - Url $SharePointSiteURL - UseWebLogin
- # sharepoint online create folder powershell
- Add - PnPFolder - Name $FolderName - Folder $RelativeURL - ErrorAction Stop
- Write - host - f Green "New Folder '$FolderName' Added!"
- } catch {
- write - host "Error: $($_.Exception.Message)" - foregroundcolor Red
- }
Conclusion
We can automate the above process to call any kind of verified, tested PS scripts from a master PS script file and run it across a CMD, Windows ISE, PowerShellManagement Shell Tool, or Azure PS Runbook, and implement scheduled timer automated web jobs also established using the above simple process.
Sharing is Caring!
Cheers!!

Join the conversation! Your thoughts help the community grow.