import depuis ancien GitHub
This commit is contained in:
49
deploy-remove-old-tasks/RemoveOldTask.ps1
Normal file
49
deploy-remove-old-tasks/RemoveOldTask.ps1
Normal file
@@ -0,0 +1,49 @@
|
||||
$dataSource = "InstanceBDD"
|
||||
$user = "usrlandeskRead"
|
||||
$PassSQL = 'password'
|
||||
$database = "LDMS"
|
||||
|
||||
$connectionString = "Server=$dataSource;uid=$user; pwd=$PassSQL;Database=$database;Integrated Security=False;"
|
||||
$connection = New-Object System.Data.SqlClient.SqlConnection
|
||||
$connection.ConnectionString = $connectionString
|
||||
$connection.Open()
|
||||
$query = "SELECT * FROM [LDMS].[dbo].[LD_TASK]"
|
||||
$command = $connection.CreateCommand()
|
||||
$command.CommandText = $query
|
||||
$result = $command.ExecuteReader()
|
||||
$table = new-object System.Data.DataTable
|
||||
$table.Load($result)
|
||||
|
||||
$currentdate = get-date
|
||||
|
||||
$mycreds = Get-Credential -Credential "domaine\dwuibail_adm"
|
||||
$ldWS = New-WebServiceProxy -uri http://serverlandesk.leblogosd.lan/MBSDKService/MsgSDK.asmx?WSDL -Credential $mycreds
|
||||
|
||||
write-host "************************** list ask **************"
|
||||
foreach ($element in $table) {
|
||||
$Nomtache = $element.TASK_NAME
|
||||
$next = $element.NEXT_START
|
||||
$taskid = $element.LD_TASK_IDN
|
||||
|
||||
$Retentionday = 30
|
||||
If($Nomtache -like "*EN-BE*"){ $Retentionday = 2 }
|
||||
|
||||
If(($Nomtache -notlike "*PORTAL*") -and ($Nomtache -notlike "*Download patch content*")){
|
||||
write-host $Nomtache
|
||||
if ($next -like "*/*") {
|
||||
$next = [DateTime]$next
|
||||
|
||||
$ts = New-TimeSpan -Start $next -End $currentdate
|
||||
$nbday = $ts.Days
|
||||
write-host "Nombredejours=$nbday"
|
||||
if($nbday -gt $Retentionday) {
|
||||
Write-host "delete=$taskid" -ForegroundColor Yellow
|
||||
$ldWS.DeleteTask($taskid)
|
||||
}
|
||||
} Else {
|
||||
#Write-host "delete=$taskid" -ForegroundColor Yellow
|
||||
}
|
||||
write-host $next
|
||||
write-host " "
|
||||
}
|
||||
}
|
||||
33
deploy-remove-old-tasks/readme.md
Normal file
33
deploy-remove-old-tasks/readme.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Remove Old Scheduled Tasks (Ivanti EPM)
|
||||
Deletes outdated **scheduled tasks** from Ivanti EPM based on the next run date in `LD_TASK`, with simple name-based exclusions, via MBSDK (`MsgSDK.asmx`).
|
||||
|
||||
## Requirements
|
||||
- Windows PowerShell 5.1
|
||||
- Read access to SQL database `LDMS` (table `dbo.LD_TASK`)
|
||||
- Network access to the EPM Core MBSDK endpoint
|
||||
- Account permitted to delete tasks via MBSDK
|
||||
|
||||
## Configure (top of script)
|
||||
```powershell
|
||||
$dataSource = "InstanceBDD" # SQL Server/instance
|
||||
$user = "usrlandeskRead" # SQL read-only login
|
||||
$PassSQL = "password" # SQL password
|
||||
$database = "LDMS" # Database
|
||||
|
||||
$mycreds = Get-Credential -Credential "domaine\\dwuibail_adm" # EPM account
|
||||
$ldWS = New-WebServiceProxy -Uri "http://serverlandesk.leblogosd.lan/MBSDKService/MsgSDK.asmx?WSDL" -Credential $mycreds
|
||||
```
|
||||
|
||||
## Behavior
|
||||
Loads dbo.LD_TASK and iterates tasks:
|
||||
-- Default retention: 30 days
|
||||
-- Skips names matching *PORTAL* and *Download patch content*
|
||||
|
||||
When NEXT_START is older than retention, calls:
|
||||
-- $ldWS.DeleteTask($taskid)
|
||||
|
||||
|
||||
## Run
|
||||
```powershell
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\Remove-OldScheduledTasks.ps1
|
||||
```
|
||||
Reference in New Issue
Block a user