27 lines
911 B
PowerShell
27 lines
911 B
PowerShell
# Specify the directory containing the scripts
|
|
$scriptDirectory = "C:\Scripts\Tasks\System-Tasks"
|
|
|
|
# Get all Batch and PowerShell scripts in the directory
|
|
$scriptsToRun = Get-ChildItem -Path $scriptDirectory -Filter "*.bat"
|
|
$psScripts = Get-ChildItem -Path $scriptDirectory -Filter "*.ps1"
|
|
$scriptsToRun += $psScripts
|
|
|
|
# Iterate through the script paths and execute each one
|
|
foreach ($script in $scriptsToRun) {
|
|
try {
|
|
# Execute the script based on its extension
|
|
if ($script.Extension -eq ".ps1") {
|
|
# Execute PowerShell script
|
|
& "$($script.FullName)"
|
|
} else {
|
|
# Execute Batch script
|
|
& "$($script.FullName)"
|
|
}
|
|
|
|
Write-Host "Script '$script' executed successfully."
|
|
Start-Sleep -Seconds 5 # Adjust the delay as needed
|
|
} catch {
|
|
Write-Warning "Error executing '$script': $($_.Exception.Message)"
|
|
}
|
|
}
|