c7c4c7
asked on
How do I call powershell scripts from a config file
I have several sites that I maintain and use powershell scripts to keep me up to date with what is going on at the different machines. Problem is that none of them are configured exactly the same so I have to customize the main scripts at each site to fit their need.
I would like to change that by having a config file with only the names of the scripts that are needed for that site and just have one script that calls that config file to call all of the required scripts
I've looked all over and don't see anything that points me in the right direction. Can you either show me how to do it or point me to a site that details the implementation for me.
Thanks
I would like to change that by having a config file with only the names of the scripts that are needed for that site and just have one script that calls that config file to call all of the required scripts
I've looked all over and don't see anything that points me in the right direction. Can you either show me how to do it or point me to a site that details the implementation for me.
Thanks
What do you need to customize? Just variables?
Sorry but I'm not understanding what you're looking to do.
Sorry but I'm not understanding what you're looking to do.
ASKER
footech - As an example not all machine have the same backup software, so rather than modify a machines script to check either for all backup software or just a specific software I want to be able to create a single script that will call different scripts based on that machines needs.
asavener - I'll check that out and get back to you
Thanks
asavener - I'll check that out and get back to you
Thanks
Using a folder only containing the necessary scripts for each machine is a good idea. Of course you could also put all scripts including the caller script into the same folder, and exclude the own name from being executed again. The current script (with full path) is stored in $myInvocation.get_MyComman d().Defini tion. so checking the file name against that allows to skip the own script.
Or you use the same naming convention for the "satellite" scripts, like all starting with 'maint-'.
Or you use the same naming convention for the "satellite" scripts, like all starting with 'maint-'.
ASKER
asavener- As I understand your implementation you will put all scripts for a site in a folder and then execute all scripts that are in that folder.
That's not what I had in mind when I asked the question. I don't want to have to worry about what script goes where, I load all scripts on every machine. That way I don't have to keep track if the right script is on the correct machine.
Currently I have a directory of current scripts when I make changes to a script, or add one, I just copy the whole directory to every machine and I know all machines are up to date.
I currently have a driver script that blindly call all of the other scripts, but because not all machines are configured the same the results of some scripts can make it look like there is a problem when there isn't.
With all scripts loaded on all machines I want the driver script to read a config file, that contains just the names of the scripts I want to run on that machine and driver script will only run those scripts. When I run the daily scripts if I don't need one anymore I remove its name from the file and also if I need to start running a script I can just add the name to the file.
No more erratic results
That's not what I had in mind when I asked the question. I don't want to have to worry about what script goes where, I load all scripts on every machine. That way I don't have to keep track if the right script is on the correct machine.
Currently I have a directory of current scripts when I make changes to a script, or add one, I just copy the whole directory to every machine and I know all machines are up to date.
I currently have a driver script that blindly call all of the other scripts, but because not all machines are configured the same the results of some scripts can make it look like there is a problem when there isn't.
With all scripts loaded on all machines I want the driver script to read a config file, that contains just the names of the scripts I want to run on that machine and driver script will only run those scripts. When I run the daily scripts if I don't need one anymore I remove its name from the file and also if I need to start running a script I can just add the name to the file.
No more erratic results
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
IMHO there isn't much of a difference between the "execute all scripts in a customized folder" and "execute all scripts I have enumerated" in regard of making mistakes. If you introduce a new script, you will now push it to all machines (ok), but then need to remember to include it in all or the relevant machines' config files.
Further, it doesn't make sense to me to have a copy of all scripts on all machines. Use a central repository server instead, and let the caller script do the work! I even can imagine to have a single, central config file including either a machine-script or script-machine relation.
Further, it doesn't make sense to me to have a copy of all scripts on all machines. Use a central repository server instead, and let the caller script do the work! I even can imagine to have a single, central config file including either a machine-script or script-machine relation.
And if you want to maintain your idea of one config file per machine, no issue with that, but I definitely would use config files including ALL scripts with a boolean to mark those to execute. That way you can always check for added scripts you might have not configured to run yet.
Another option would be to create an array with the names/paths of the scripts you want to run. Create a list of all scripts, and then comment out the ones you don't want to run.
You could use a variable for the path, if you don't always put the scripts in the same path.
Another option is a CSV file with the scripts you want to run. Just import the list into an array.
You could use a variable for the path, if you don't always put the scripts in the same path.
Another option is a CSV file with the scripts you want to run. Just import the list into an array.
ASKER
Qlemo - I like your addition of the Boolean please give an example building on what footech has all ready submitted
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help.
$ScriptPath = <somepath>
$PluginsFolder = $ScriptPath + "\Plugins\"
$Plugins = Get-ChildItem -Path $PluginsFolder -filter "*.ps1" | Sort Name
Foreach ($plugin in $Plugins) {
Invoke-Settings -Filename $plugin.Fullname
}