Wednesday, November 27, 2013

more commands and scripts


getting remote command line\process path
wmic /node:10.1.2.3 PROCESS get Caption,Commandline,Processid

IIS Logs (from friend)

Purpose:                              Removes IIS log files older than 30 days and sets the compress switch on all files older than 3 days. This is to save space on the log drive and
                automatically manage IIS log file retention on Exchange CAS servers.

#>
# Variables
$dateNow = (Get-Date).ToString("HHmm_ddMMyyyy")
$deleteDate = (Get-Date).addDays(-30)
$CompressDate = (Get-Date).addDays(-3)


#MAIN SCRIPT
# Cleanup IIS files older than 30days old
Get-ChildItem D:\IIS_Logs -Recurse | where {$_.CreationTime -le $deleteDate -and $_.Attributes -notlike "*Directory*"} | Remove-Item -force
# Compress IIS files created more than 3days ago (omit Directories)
$IISFiles = Get-ChildItem D:\IIS_Logs -Recurse | where {$_.CreationTime -le $CompressDate -and $_.Attributes -notlike "*Compress*" -and $_.Attributes -notlike "*Directory*"} | Select *
foreach($file in $IISFiles){
Invoke-WmiMethod -Path "CIM_DataFile.Name='$($File.FullName)'" -Name compress -Confirm:$false

}

1 comment:

SimonM said...

LOL I like this one can I use it?... ;)