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 :-)

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:WindowsCCM')
                Get-ChildItem -Path 'C:WindowsCCMLogs' -File -Include .log | foreach {
                    Remove-Item $_.FullName -force

Howto hide a PowerShell prompt


Today I was asked a question… how to hide a PowerShell window.
In this specific scenario a script was executed by calling the PowerShell.exe executable with some appropriate parameters:

PowerShell.exe -WindowStyle Hidden -File D:MyScript.ps1

But… what if you have no such luxury? What if you only have a script and no control over how it’s called, yet you do want to hide the screen so that the user doesn’t see it?
Put the following code at the top of your script:

Add-Type -Name win -MemberDefinition '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);' -Namespace native
[native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle,0)

Well, it’s not hiding entirely (one sees a prompt for an instance) but it’s pretty darn close :-)

Use PowerShell to get the default IIS log directory


Part of an inventory I did for a customer were some defaults of their IIS configuration.
Here’s a oneliner to get the default log directory from IIS:

(Get-WebConfigurationProperty '/system.applicationHost/sites/siteDefaults' -Name 'logfile.directory').Value
  • ISESteroids

  • Pluralsight

  • Sapien

Go to Top