Tuesday, 10 March 2020

powershell script to trigger message in slack using web hock



    $uriSlack = "URL"
        $body = ConvertTo-Json @{
        pretext = "test"
        text = "test"
        color = "#142954"
}
try {
    Invoke-RestMethod -uri $uriSlack -Method Post -body $body -ContentType 'application/json' | Out-Null
    } catch {
    Write-Error (Get-Date) ": Update to Slack went wrong..."
    }

python script to List Files from a directory created or modified in last 30 min





$path = "Z:\"+(Get-Date).tostring("MM-dd-yyyy")
#$path
$FileList = Get-ChildItem -Path $path
$FileLists = $FileList| Where-Object {$_.LastWriteTime -gt [datetime]::Now.AddMinutes(-30)}
#$FileLists

$currenttime = (Get-Date).ToString('HH:mm')
#$currenttime

$currenttime1 = (Get-Date).AddMinutes(1).ToString('HH:mm')
#$currenttimeplus1

$currenttime2 = (Get-Date).AddMinutes(2).ToString('HH:mm')
#$currenttimeplus2

$currenttime3 = (Get-Date).AddMinutes(3).ToString('HH:mm')
#$currenttimeplus3

$currenttime4 = (Get-Date).AddMinutes(4).ToString('HH:mm')
#$currenttimeplus4

$currenttime5 = (Get-Date).AddMinutes(5).ToString('HH:mm')
#$currenttimeplus5

$currenttime6 = (Get-Date).AddMinutes(6).ToString('HH:mm')
#$currenttimeplus6

$currenttime7= (Get-Date).AddMinutes(7).ToString('HH:mm')
#$currenttimeplus7
$currenttime8 = (Get-Date).AddMinutes(8).ToString('HH:mm')
#$currenttimeplus8
$currenttime9 = (Get-Date).AddMinutes(9).ToString('HH:mm')
#$currenttimeplus9
$currenttime10 = (Get-Date).AddMinutes(10).ToString('HH:mm')
#$currenttimeplus10

#Write-Host "in for loop"
#$filecreatedtime = $tomail.CreationTime.ToString('HH:mm')
#$filecreatedtime

$counter = 0   
foreach ($tomail in $FileLists)
{
<#
Write-Host "in for loop"
Write-Host ($tomail)
Write-Host ("----------------------------------------------------------")
Write-Host ($tomail.CreationTime.ToString('HH:mm'))
Write-Host ($currenttime)
Write-Host ("----------------------------------------------------------")
#>
$counter = 0
if ($tomail.Name -match '')
{
#Write-Host $tomail.Name
if ($([DateTime]$tomail.CreationTime.ToString('HH:mm')) -match $([DateTime]$currenttime) -or $([DateTime]$currenttime1) -or $([DateTime]$currenttime2) -or $([DateTime]$currenttime3) -or $([DateTime]$currenttime4) -or $([DateTime]$currenttime5) -or $([DateTime]$currenttime6) -or $([DateTime]$currenttime7) -or $([DateTime]$currenttime8) -or $([DateTime]$currenttime9) -or $([DateTime]$currenttime10))

    {
        #Write-Host "File  found"

        $counter = $counter + 1

        $tomail.Name + "  Found  " + $tomail.CreationTime >> C:\Users\raghuvel.sekar\Desktop\LOG.txt

}
   
else
{
  #Write-Host "File not found"

  "  FileNotFound  " + $currenttime >> C:\Users\raghuvel.sekar\Desktop\LOG.txt

}
        #$counter
        Remove-Variable counter

python script to send mail using outlook 2016 with multiple attachment




 $Outlook = New-Object -ComObject Outlook.Application
 $createmail = $Outlook.CreateItem(0)
 $createmail.To =  "test@test.com"
 $createmail.Subject = "test"
 $createmail.Body = "test"
 $file = "C:\Users\raghuvel.sekar\Desktopscreenshot3.jpg"
 $file1 = "C:\Users\raghuvel.sekar\Desktop\creenshot4.jpg"
 $createmail.Attachments.Add($file)
 $createmail.Attachments.Add($file1)
 $createmail.Send()

Python to get only digits from a file and append into a list



            f = open('file2.txt', 'r')
            for line in f:
                    words = line.split()
                    for i in words:
                            if(i.isdigit()):
                                mylist.append(i)
            print (mylist)

take a screenshot with python , convert image into text and save it as a file




try:
    from PIL import Image
except ImportError:
    import Image
import pytesseract
import sys, os
import subprocess
import pyautogui


pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

img1 = pyautogui.screenshot(region=(372,198,1118,682))
img1.save("screenshot1.jpg")


saved_stdout = sys.stdout
sys.stdout = open('file.txt', 'w')
print (pytesseract.image_to_string(Image.open('screenshot1.jpg')))
sys.stdout.close()
sys.stdout = saved_stdout

Monday, 3 February 2020

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...