Created
March 8, 2019 19:29
-
-
Save prakash-patel/5bc9868f3129e34948c814a9f910c740 to your computer and use it in GitHub Desktop.
Powershell IIS Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#PART-1 Export IIS Application into Excel | |
import-module webadministration | |
$servername = $env:computername | |
get-website | select name,id,state,physicalpath, | |
@{n="Bindings"; e= { ($_.bindings | select -expa collection) -join ';' }} , | |
@{n="LogFile";e={ $_.logfile | select -expa directory}}, | |
@{n="attributes"; e={($_.attributes | % { $_.name + "=" + $_.value }) -join ';' }} | | |
Export-Csv -NoTypeInformation -Path C:\iis-sites.csv | |
#PART-2 Generate anchor tag link for all IIS application site. | |
$hostname = "localhost" | |
Foreach ($Site in get-website) { | |
Foreach ($Bind in $Site.bindings.collection) { | |
$data = [PSCustomObject]@{ | |
name=$Site.name; | |
Protocol=$Bind.Protocol; | |
Bindings=$Bind.BindingInformation | |
} | |
$data.Bindings = $data.Bindings -replace '(:$)', '' | |
$html = "<a href=""" + $data.Protocol + "://" + $data.Bindings + """>" + $data.name + "</a>" | |
$html.Replace("*", $hostname); | |
} | |
} | |
#PART-3 Get List of application form IIS | |
Import-Module Webadministration | |
Get-ChildItem -Path IIS:\Sites | |
#PART-4 Get List of Application from IIS in Loop | |
Foreach ($Site in get-website) { Foreach ($Bind in $Site.bindings.collection) { [pscustomobject]@{name=$Site.name;Protocol=$Bind.Protocol;Bindings=$Bind.BindingInformation; path=$Site.physicalPath }}} | |
#PART-5 Delete App Pool for particular user. | |
#Deleting Sites and app pools in IIS 7 with PowerShell | |
$appCmd = "C:\windows\system32\inetsrv\appcmd.exe" | |
#lists all the sites | |
& $appcmd list site | |
#deletes a specific site | |
& $appcmd delete site "BoxTracking" | |
#deletes a specific application pool | |
& $appcmd delete apppool "BoxTracking" | |
#delete any app pools that use a certain username (in the identity column of the GUI) | |
$account = "" # add user account {domain/username} | |
$AppPools = & $appcmd list apppool /processModel.userName:$account | |
foreach ($pool in $AppPools){ | |
$pool = $pool.split(" ")[1] #get the name only | |
& $appcmd delete apppool $pool | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment