Skip to content
gpawade edited this page Mar 23, 2018 · 2 revisions

Powershell

https://docs.microsoft.com/en-us/powershell/scripting/getting-started/basic-cookbooks?view=powershell-5.1

Helpfull Command

$ Get-Command                 # Return all command list
$ Get-Command *site*          # Return all command contain word site

$ Get-ChildItem Env:           # Display List of environment variable
$ Test-Path                    #  Determines whether path exist

$ Invoke-RestMethod             # Send an http request to a  RESTFUL web service

Variable

$Env:VariableName           # Return the enviroment variable value
$_                          # Current pipeline object
$Args                       # Argument to script function

IIS Management

https://docs.microsoft.com/en-us/powershell/module/webadminstration/?view=winserver2012-ps

Import-Module WebAdministration

New-Website -Name mypoc.com -HostHeader mypoc.com -PhysicalPath D:\Site\mysite.com

Create web application under web site

New-WebApplication -Site "Default Web Site" -Name MusicWorld -PhysicalPath c:\inetpub\wwwroot\MusicWorld -Force

WebAppPool

New-WebAppPool -Name MyPOC.com -Force

Check site exist

 get-website | where-object { $_.name -eq 'MyWebsite1' }

 if($(Get-Website | Where-Object { $_.name -eq "mysite" }) -eq $null ){ Write-Host "Not Exist" }

Check App Pool Exist

Test-Path "IIS:\AppPool\appppol_name"

Modify the AppPool process model setting

Set-ItemProperty "IIS:\AppPools\MyPOC.com" -name "processModel" -Value @{ idleTimeout="00:40:00"}

Rapid - Fail Protection

Set-ItemProperty "IIS:\AppPools\MyAppPool" -name "failure" -Value @{
    orphanWorkerProcess="True"; # Or False
    orphanActionExe="C:\MyorphanScript.exe"; 
    orphanActionParams="-Parameter 'orphan'";
    loadBalancerCapabilities="TcpLevel"; # HttpLevel
    rapidFailProtection="False"; # Or True
    rapidFailProtectionInterval="00.00:07:00";
    rapidFailProtectionMaxCrashes=10;
    autoShutdownExe="C:\MyShutdownExe.exe"; 
    autoShutdownParams="-parameter 'ShutdownExe'";
}

Funciton

Creating funciton in file

function Get-MyResult{
    param($a, $b)

    Write-Host "param are $a and $b
}
Call function in another script
. c:\myfunc.ps1

Get-MyResult -a 12 -b 324