Quantcast
Viewing latest article 43
Browse Latest Browse All 120

A script to delete ConfigMgr client logs on remote devices

At one of my customers I’m part of a project team where we needed to start with a ‘fresh’ set of SCCM logs on the clients because that would make our troubleshooting a bit easier.
So, here’s a handy little script to remove the ConfigMgr client logs from a bunch of servers, which are queried from the Active Directory Image may be NSFW.
Clik here to view.
:-)

Note that this is purely quick and dirty… there is no error handling or logging whatsoever.

$Servers = Get-ADComputer -Filter {samaccountname -like "SRV-RDS*"}
foreach ($Server in $Servers)
{
    if (Test-Connection -ComputerName $Server.Name -Quiet)
    {
        invoke-command -ComputerName $Server.Name -ScriptBlock {
            if (Test-Path -Path 'C:\Windows\CCM')
            {
                Get-ChildItem -Path 'C:\Windows\CCM\Logs' -File -Include .log | foreach {
                    Remove-Item $_.FullName -force
                }
            }
        }
    }
}

Viewing latest article 43
Browse Latest Browse All 120

Trending Articles