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

}

Monday, November 4, 2013

powershell filtering two arrays and using text and variables

Comparing two list/Array/ and work from that...
#
# Active FPS list
#

$OUName= 'OU=File and Print,OU=Servers,OU=MOE Servers,DC=Kool,DC=Kids'
$TheComputers = Get-ADComputer -filter * -searchbase $OUName

#
# Exclude File and Print Server
# ,,
#
$ExcludedFPs="PANDA"
Write-host Excluded File and Print Server - $ExcludedFPs

#Filter the List of objects
$AcutalFPStargets=Compare-Object $TheComputers.name $ExcludedFPs | where {$_.sideindicator -eq "<="} | % {$_.inputobject}

#now... do stuff 
foreach ($server in $AcutalFPStargets){
Variables in text.. so I can remember sometimes need brackets othertimes not... @#$@#
if(!($user.homedirectory -like '*'+($server).name+'*'))

$path = "\\"+$server.Name+"\users"