Sunday 23 May 2021

REGEX Match


$a=Read-Host "Enter Value : "

if($a -match '^(sumant|ajay|kumar)' ){

    Write-Output "Matched"

}

else {

    Write-Output "Not Matched"



Monday 3 May 2021

Start-Process with a Special Name or Handle to Kill It


Write-Output " Creating a new PowerShell Session"

$arg = {"$Host.UI.RawUI.WindowTitle='MySession'";"&'F:\Scripts\LicMgmt .ps1'";}

$StartInfo = new-object System.Diagnostics.ProcessStartInfo

$StartInfo.FileName = "$pshome\powershell.exe"

$StartInfo.Arguments = $arg

[System.Diagnostics.Process]::Start($StartInfo) 


To Check your Open Session/Kill It

Get-Process|where-object{($_.MainWindowTitle) -match '^(Select MySession|MySession)'}|Stop-Process