26 lines
864 B
PowerShell
26 lines
864 B
PowerShell
# Specify the directory containing the scripts
|
|
$scriptDirectory = "C:\Scripts\Tasks\System-Tasks"
|
|
|
|
# Get all files and then filter within the loop
|
|
$scriptsToRun = Get-ChildItem -Path $scriptDirectory
|
|
|
|
foreach ($script in $scriptsToRun) {
|
|
if ($script.Extension -in ".ps1", ".bat") { # Check if the extension is .ps1 or .bat
|
|
try {
|
|
Write-Host "Executing script: $($script.FullName)"
|
|
|
|
if ($script.Extension -eq ".ps1") {
|
|
& powershell -File "$($script.FullName)" # -NoProfile, -ExecutionPolicy as needed
|
|
} else {
|
|
Start-Process -FilePath "$($script.FullName)" -Wait
|
|
}
|
|
|
|
Write-Host "Script '$($script.FullName)' executed successfully."
|
|
Start-Sleep -Seconds 5
|
|
|
|
} catch {
|
|
Write-Warning "Error executing '$($script.FullName)': $($_.Exception.Message)"
|
|
}
|
|
} #end extension check
|
|
}
|