ServiceNow - Delete files from CI using Mid Server

bhakti2
Tera Contributor

Hello,

We want to delete files from a particular CI that is discovered by the Mid Server. We have the Mid Server credentials along with the CI names.

How can we achieve this?

5 REPLIES 5

adarsh_07
Tera Contributor

Hi, can u explain a little bit more about this requirement?

Hello,

We received alerts from particular source on the Service Now instance. These alerts contain system information and the paths of log files. We need to delete those logs from the system.

But, initially they provided us the mid server name and CI name and Path of log files to delete.

Folder location:
C:\inetpub\logs\LogFiles\W3SVC1


is it possible to delete files from C drive of CI ?

Okay ,if u have path for that file then u should use powershell script like:

$filePath = "C:\inetpub\logs\LogFiles\W3SVC1"    //Define the file path to delete

if (Test-Path $filePath) {
Remove-Item $filePath -Force                      // Delete the file

Write-Output "File $filePath deleted successfully."
} else {
Write-Output "File $filePath does not exist."
}

and if u want to perform this through orchestration activity then,
goto Orchestration->Activity Designer Activity, and use the powershell command with stored activities,like:
var command = 'powershell.exe -File "C:\inetpub\logs\LogFiles\W3SVC1";
var probe = new SNC.PSProbe();
var output = probe.executeProbe('MidServerName', command, 'cred_name');
gs.print(output);

Hope this can help,Thanks


Thank you for response. 
Could you please explain more. As in this script configuration item name is not mentioned.