Posts

Powershell send e mail

Powershell send e mail: $From = "pugazh@pugazh.in" $To = "pugazh@pugazh.in" $Subject = "Here's the Email Subject" $Body = "This is what I want to say" $SMTPServer = "smtp.hostinger.in" $SMTPPort = "587" Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential (Get-Credential) –DeliveryNotificationOption OnSuccess

Powershell to check the public IP and trigger the mail

$IPstatus = Invoke-WebRequest -Uri "https://whatismyipaddress.com/ip/4.4.4.8" -Headers @{"Referer"="https://www.google.com/"; "User-Agent"="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"} If ($IPstatus.StatusDescription -eq 'ok') {send-mailmessage -smtpserver smtp.office365.com -to pugazh@pugazh.co.in -from report@pugazh.co.in -subject 'MPLS Link is UP now' -Port 25} Refer: Link

Power shell - Deleting files and folders older than X days

#delete files older than 30 days Get-ChildItem $Folder -Recurse -Force -ea 0 | ? {!$_.PsIsContainer -and $_.LastWriteTime -lt (Get-Date).AddDays(-30)} | ForEach-Object {    $_ | del -Force    $_.FullName | Out-File C:\log\deletedbackups.txt -Append } #delete empty folders and subfolders if any exist Get-ChildItem $Folder -Recurse -Force -ea 0 | ? {$_.PsIsContainer -eq $True} | ? {$_.getfiles().count -eq 0} | ForEach-Object {     $_ | del -Force     $_.FullName | Out-File C:\log\deletedbackups.txt -Append }

Powershell to export COMPUTER list from OU

Powershell to export COMPUTER list from OU: Get-ADcomputer -Filter * -SearchBase 'OU=Windows 7 Desktops,OU=Workplace,DC=PUGAZH,DC=COM' -Properties Name,CanonicalName,DistinguishedName,Description,Enabled,OperatingSystem | select-object Name,CanonicalName,DistinguishedName,Description,Enabled,OperatingSystem | Sort-Object -Property Name | Export-Csv AllComputers_2019.csv

Newly Created Scheduled Tasks Event ID 4698

Hi If we created the new Scheduled Tasks, Event ID 4698 will appear in the  Security log.

Find who joined a computer to a domain

Find w ho joined a computer to a domain $NoInfo = $null $Offline = $null $List = $null #Get-Content unknowns.txt | foreach { Get-ADComputer -Filter 'OperatingSystem -like "*Windows server*"' -Properties * | foreach { $FQDN = $_.DNSHostName $Path = "\\$FQDN\c`$\Windows\debug\NetSetup.log" if (Test-Connection $FQDN -Count 1 -ErrorAction SilentlyContinue) { if (Test-Path $Path) { write-host "`n`nChecking $FQDN..." $User = ($($(Select-String -Path $Path -Pattern "lpAccount: " -CaseSensitive) -split " ")[3]) $User [array]$List += Write-Output $FQDN";"$User } else {[array]$NoInfo += $FQDN} } else {[array]$Offline += $FQDN} #sleep 5 } $list

Apply once and do not reapply

Apply once and do not reapply: FilterRunOnce which is also associated a unique id. This looks like -          During the first application, the UID will be stored in the registry (User: HKCU\Software\Microsoft\Group Policy\Client\RunOnce Computer: HKLM\Software\Microsoft\Group Policy\Client\RunOnce). At the second application of the GPP, the CSE will check if the key with the UID already exists and if yes, it does not apply the GPP any more. Force Group Policy to Reapply Settings If you want to make sure that security settings in a GPO are applied every time Group Policy is processed, regardless of whether the GPO has changed, there are four Group Policy settings that you should enable. You can find them under Computer Configuration > Administrative Templates > System > Group Policy. Configure security policy processing Configure registry policy processing Configure scripts policy processing Configure IP security policy proc...