PowerShell script to Export and Disable scheduled tasks

#Define the task path

$taskPath = “\”

$taskPath = “\Mainstream\”

#Define output file path

$outcsv = “c:\temp\taskdef1.csv”

#Define the logic of the script

Get-ScheduledTask -TaskPath $taskPath |
Get-ScheduledTask |
ForEach-Object { [pscustomobject]@{
Name = $_.TaskName
Path = $_.TaskPath
Status = $_.State }} |

#Export the output to the defined CSV file

Export-Csv -Path $outcsv -NoTypeInformation

#Disable all task scheduler jobs inside this folder

Get-ScheduledTask -TaskPath “\” | Disable-ScheduledTask
Get-ScheduledTask -TaskPath “\Mainstream\” | Disable-ScheduledTask

Powershell scripts to validate Devops pipeline prerequisite

Validate .net version
1. Run powershell as an Administrator
2. Execute below command
Get-ChildItem ‘HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP’ -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match ‘^(?!S)\p{L}’} | Select PSChildName, version

Validate Azure CLI
1. Run Powershell as an Administrator
2. Type “AZ” and hit enter
3. If it’s running that ok otherwise download Azure CLI
https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli

Validating TLS 1.2
1. Go to Start Run
2. Enter Regedit.
Go to : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet \Control\SecurityProviders\SCHANNEL\Protocol

Validate TLS 1.2 for .Net applications
1. Login to all servers
2. Open Regedit
3. Validate if the below path exists:
‘HKLM:\SOFTWARE\Wow6432Node\Microsoft.NetFramework\v4.0.30319’
‘HKLM:\SOFTWARE\Microsoft.NetFramework\v4.0.30319’
Check if DWord entry exists – SchUseStrongCrypto
Check value of Dword – ‘1’ or ‘0’

Validate IISCrypto (SChannel and Cipher Suits)
1. Login to the server
2. Open IISCrypto tool or Download the tool from below link
https://www.nartac.com/Downloads/IISCrypto/IISCrypto.exe
3. Open the tool and take screenshots of Schannel and Cipher Suits

Validate DevOps pipeline service
1. Open services.msc
2. Check if Azure DevOps pipeline services exist

TLS Value
1. Run Powershell as an Administrator
2. Execute below command
[Net.ServicePointManager]::SecurityProtocol

Validate connectivity with the DevOps pipeline
1. Run Powershell as an Administrator
2. Execute below command
(Invoke-WebRequest -Uri status.dev.azure.com).StatusDescription

Powershell scripts to validate Active Directory

Validate Important Active Directory Services
1. Run powershell as an Administrator
2. Execute below command
$Services=’DNS’,’DFS Replication’,’Intersite Messaging’,’Kerberos Key Distribution Center’,’NetLogon’,’Active Directory Domain Services’
ForEach ($Service in $Services) {Get-Service $Service | Select-Object Name, Status}

Validate Replication on both the AD servers
1. Run powershell as an Administrator
2. Execute below command
repadmin /replsummary

Domain Controller Diagnostic tool
1. Run powershell as an Administrator
2. Execute below command
DCDiag /Test:DNS /e /v

PowerShell Script to check memory usage of a particular service

Hi All,

Below is the PowerShell script to monitor memory usage of a particular service.


####################################################################################
# Sandeep Gupta #
# Service Memory Usage Control #
####################################################################################

#Define Log File Path #
$FilePATH = $MyInvocation.MyCommand.Path -replace '\.ps1$', '.log'

#Define Service Name & Memory Threshold #
$serviceName = 'WinDefend'
$virtsize = '290'

#Server Environment#
$Servername = $env:computername

####Control function
$varService=Get-WmiObject Win32_Service -Filter "name = '$serviceName'"
$PROCESSPIDs = $varService.ProcessID
$varProcessMem = Get-WmiObject Win32_Process -Filter "ProcessId = '$PROCESSPIDs'"
$MemSizeBy = $varProcessMem.WS
$MemSizeFl = $MemSizeBy/1MB
$MemSize = [int]$MemSizeFl

#Test and Alert Function#
write-host "$virtsize : $MemSize"
If ($MemSize -gt $virtsize) {

Write-Host "Service is taking more memory"
Add-Content $FilePATH "$serviceName Memory Usage is more than $virtsize MB : $MemSize MB"
}
else
{
Add-Content $FilePATH "$serviceName Memory Usage is less than $virtsize MB : $MemSize MB"
Write-Host "Service is taking less memory"
}



Powershell script to get 500 status from IIS logs

Set Time Variable -30

$time = (Get-Date -Format “HH:mm:ss”(Get-Date).addminutes(-30))

Location of IIS LogFile

$File = “C:\Logs\IIS\”+”u_ex”+(get-date).ToString(“yyMMdd”)+”.log”

Get-Content gets the file, pipe to Where-Object and skip the first 3 lines.

$Log = Get-Content $File | where {$_ -notLike “#[D,S-V]*” }

Replace unwanted text in the line containing the columns.

$Columns = (($Log[0].TrimEnd()) -replace “#Fields: “, “” -replace “-“,”” -replace “(“,”” -replace “)”,””).Split(” “)

Count available Columns, used later

$Count = $Columns.Length

Strip out the other rows that contain the header (happens on iisreset)

$Rows = $Log | where {$_ -like “500 0 0“}

Create an instance of a System.Data.DataTable

Set-Variable -Name IISLog -Scope Global

$IISLog = New-Object System.Data.DataTable “IISLog”

Loop through each Column, create a new column through Data.DataColumn and add it to the DataTable

foreach ($Column in $Columns) {
$NewColumn = New-Object System.Data.DataColumn $Column, ([string])
$IISLog.Columns.Add($NewColumn)
}

Loop Through each Row and add the Rows.

foreach ($Row in $Rows) {
$Row = $Row.Split(” “)
$AddRow = $IISLog.newrow()
for($i=0;$i -lt $Count; $i++) {
$ColumnName = $Columns[$i]
$AddRow.$ColumnName = $Row[$i]
}
$IISLog.Rows.Add($AddRow)
}
$IISLog | select @{n=”Time”; e={Get-Date -Format “HH:mm:ss”(“$($_.time)”)}},csuristem,scstatus | ? { $_.time -ge $time }

Reference: https://stackoverflow.com/questions/20662495/powershell-script-to-monitor-iis-logs-for-500-errors-every-10-minutes