Anything learnt today?

Well this blog post is an accumulative one with one or more new learning everyday. 27th Oct 2016: The tip of the day I explored on my own was very handy. Using -Verbose and -WhatIf with Remove-Item cmdlet which gives a hint of what would happen when the cmdlet is executed. 28th Oct 2016: Difference […]

Read more "Anything learnt today?"

Powershell titbits

Convert powershell history to a PS1: To be able to select multiple items in the output grid view. $script = Get-History | Foreach-Object CommandLine | Out-GridView -PassThru or $script = Get-History | Foreach-Object CommandLine | Out-GridView -OutputMode Multiple $script | Set-Content C:\Temp\script.ps1 To be able to select only single value in the output grid view […]

Read more "Powershell titbits"

Powershell script to stop app pool, backup site content and start app pool

Import-Module WebAdministration function Get-SiteName { [cmdletBinding()] param( [Parameter(Mandatory)] $site) if(Test-Path IIS:\Sites\$site) { Write-Host “The provided website name is $site and it is a valid website`r`n” -ForegroundColor Cyan } else { Write-Host “There is not a website present in the name provided`r`n” -ForegroundColor Red Exit } } function Stop-AppPool { # Get the app pool of […]

Read more "Powershell script to stop app pool, backup site content and start app pool"

String comparison with Powershell

With PS, if you want to compare two strings, if you directly use the comparison operator -eq or -lt or so on, then the current culture is also important. If you rather want to use the ASCII values of the characters to be used for comparison then use the below two methods. [string]::Compare(‘z’,’~’,[cultureinfo]::CurrentCulture,[System.Globalization.CompareOptions]::Ordinal) [System.String]::CompareOrdinal(‘~’,’z’) ASCII […]

Read more "String comparison with Powershell"