Remotely uninstall crowdstrike

Hi Team,

I am trying to uninstall outdated crowdstrike using CsUninstallTool.exe on bunch of remote servers.

As we know we cannot directly uninstall crowdstrike, it require a maintenance code unique to host. The below script is working correctly for a single remote host but when I try to run same script, crowdstrike did not get uninstalled.

Also same script is asking for credentials after every loop and looking for optimal way to manage user session without asking cred again & again.

$servers = Get-Content 'C:\Users\PP\Desktop\CrowdStrike_Automation\servers.txt'


$maintenance_token = Get-Content 'C:\Users\PP\Desktop\CrowdStrike_Automation\maintenance_key.txt'

foreach ($server in $servers) {
 
    Invoke-Command -ComputerName $server -Credential (Get-Credential) -ScriptBlock {
        & "C:\Temp\CrowdStrike_Automation\Setup\CsUninstallTool.exe" MAINTENANCE_TOKEN=$using:maintenance_token /quiet
    }
}

Pravin,
Welcome to the forum. :wave:t4:

Since you can provide an array of computer names for the parameter -ComputerName of the cmdlet Invoke-Command you don’t need a loop at all.

Something like this should work:

$servers = Get-Content -Path 'C:\Users\PP\Desktop\CrowdStrike_Automation\servers.txt'
$maintenance_token = Get-Content -Path 'C:\Users\PP\Desktop\CrowdStrike_Automation\maintenance_key.txt'
 
Invoke-Command -ComputerName $servers -Credential (Get-Credential) -ScriptBlock {
    & "C:\Temp\CrowdStrike_Automation\Setup\CsUninstallTool.exe" MAINTENANCE_TOKEN=$using:maintenance_token /quiet
}

If you need or want to use a loop anyway you should query the needed credentials beforehand, assign it to a variable and use this variable later on to not get the credential prompt again and again … :wink:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.