วันอังคารที่ 21 พฤษภาคม พ.ศ. 2562

Copy Trend Micro Office Scan Pattern

    สวัสดีครับ เนื่องจาก ทางลูกค้ามีจำนวน Server Trend Micro Office Scan จำนวนมาก และต้องการกำหนด ให้เครื่อง Server ต่างๆ Update Pattern ช่วงหลังเวลางาน ซึ่งผ่านจาก Web Console นั้นไม่สามารถ ระบุได้ เลยได้ทำการ เขียน Powershell Scripts เพื่อทำการ Copy Pattern ไปยัง Server Trend Micro Office Scan ต่างๆ และได้ทำการเขียนเพื่อ ให้ Check old version และทำการลบ เพื่อไม่ให้เปลือง Disk ที่ Server เองด้วย




$abc=@("ondate","path","lptpath","icrcpath","lptname","locallpt","icrcname","localicrc","Rpath","Rlptpath","Ricrcpath","Rlptname","Ricrcname","abc")
$ondate = get-date -F ddMMyy

remove-item -path d:\powershell\*.txt

<# get pattern number on Local #>
$path='c:\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\'
$lptpath=$path+'lpt$vpn.*'
$icrcpath=$path+'icrc$oth.*'
<# Full name (lpt$vpn.111) #>
$lptname = Get-ChildItem $lptpath -name | select -last 1
<# lpt number #>
$locallpt = $lptname -replace 'lpt\$vpn',''
<# Full name (icrc$oth.111) #>
$icrcname = Get-ChildItem $icrcpath -name | select -last 1
<# icrc number #>
$localicrc = $icrcname -replace 'icrc\$oth',''

<# get pattern number on Remote host #>
("ip,lpt") > d:\Powershell\lpt.txt
("ip,icrc") > d:\Powershell\icrc.txt
Get-Content d:\Powershell\trendlist.csv |Foreach-Object {
($Rpath="\\$_\c$\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\"),
($Rlptpath=$Rpath+'lpt$vpn.*'),
($Ricrcpath=$Rpath+'icrc$oth.*'),
($Rlptname = Get-ChildItem $Rlptpath -name | select -last 1 ),
($Ricrcname = Get-ChildItem $Ricrcpath -name | select -last 1),
("$_,$Rlptname" >> d:\powershell\lpt.txt),
("$_,$Ricrcname" >> d:\powershell\icrc.txt)
    }

<# Prepare output file for compare #>
(Get-Content -Path "d:\Powershell\lpt.txt" -ReadCount 0) -replace 'lpt\$vpn', '' | Set-Content -Path "d:\Powershell\lptnew.txt"
(Get-Content -Path "d:\Powershell\icrc.txt" -ReadCount 0) -replace 'icrc\$oth', '' | Set-Content -Path "d:\Powershell\icrcnew.txt"

Clear-Content -Path "d:\Powershell\lpt.txt"
Clear-Content -Path "d:\Powershell\icrc.txt"
Import-Csv d:\powershell\lptnew.txt | Where-Object {$_.lpt -lt "$locallpt" -and $_.lpt -gt "$null"} | ForEach-Object {($_).ip >> d:\Powershell\lpt.txt}

Get-Content -Path "d:\Powershell\lpt.txt" | ForEach-Object {
    ($Rpath="\\$_\c$\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\"),
    (Copy-Item -Path $path$lptname -Destination $Rpath),
    ((echo "$_,LPT") >> d:\log\$ondate.csv)
    }

Import-Csv d:\powershell\icrcnew.txt | Where-Object {$_.icrc -lt "$localicrc" -and $_.icrc -gt "$null"} |  ForEach-Object {($_).ip >> d:\Powershell\icrc.txt}

Get-Content -Path "d:\Powershell\icrc.txt" | ForEach-Object {
    ($Rpath="\\$_\c$\Program Files (x86)\Trend Micro\OfficeScan\PCCSRV\"),
    (Copy-Item -Path $path$icrcname -Destination $Rpath),
    ((echo "$_,ICRC") >> d:\log\$ondate.csv)
    }


remove-item -path d:\powershell\*.txt
$abc  | foreach-object {remove-variable $_}



ไม่มีความคิดเห็น:

แสดงความคิดเห็น