Mark Minasi's Tech Forum
Register Calendar Latest Topics Chat
 
 
 


Reply
  Author   Comment  
meloao

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 30
Reply with quote  #1 
I have over 20 Powershell scripts that I want to run on a schedule.  Ultimately, I want to have 1 "master" script that will run the others in the folder via task scheduler.

The master script is below:

$folderLocation = "C:\scripts\"

$items = Get-ChildItem -Path $folderLocation

foreach ($item in $items)
{

if ($item.Attributes -ne "Directory")
{

Invoke-Expression "$folderLocation$item"

}
}

When I run the master Powershell script it runs the 3 other Powershell scripts I have in the folder so far.  However, it keep re-running the same scripts over and over.   I only want the master script to run the other scripts once.

0
meloao

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 30
Reply with quote  #2 
SMH, okay figured it out.  I had the master script in the same folder as the other Powershell scripts so it running in continuous loop.  Once I put the master script outside the folder, then the other scripts ran 1 time only!
0
Pieter

Avatar / Picture

Senior Member
Registered:
Posts: 130
Reply with quote  #3 
Or use exclude :

$items=Get-ChildItem -Path $folderLocation -Exclude "MasterScript.ps1"


__________________
Pieter Demeulemeester
0
meloao

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 30
Reply with quote  #4 
Good one Pieter!  Thank you!  The "-Exclude" parameter is good to know!
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation: