Link to home
Start Free TrialLog in
Avatar of divetennis
divetennis

asked on

Windows IIS Powershell help.

Hi there,

I need some help write a powersheet so that when i run it on my IIS 7 or 7.5 it will check if each of this exisit. If exisit, it will throw a statement, "exisit, please have it removed"

http://localhost/iissamples
http://localhost/iisadmpwd
http://localhost/IISHelp
http://localhost/Printers

I want to ensure that  the default Virtual Directories and the files and folder they point to should be removed.
Avatar of Dorababu M
Dorababu M
Flag of India image

I had this code which was written to list out all the sites in IIS, and will start the sites which has been stopped. Modify it as per your need

try
{
    Import-Module WebAdministration
    Get-WebApplication
 
    $webapps = Get-WebApplication
    $list = @()

    foreach ($webapp in get-childitem IIS:\Sites\)
    {
        $name = "IIS:\Sites\" + $webapp.name
        $item = @{}
 
        $item.WebAppName = $webapp.name
        #$item.Version = (Get-ItemProperty $name managedRuntimeVersion).Value
        $item.State = $webapp.state 
        if( $item.State -eq 'Stopped')
        {
            Get-Website -Name $item.WebAppName | Start-Website
        }
        $obj = New-Object PSObject -Property $item
        $list += $obj
    }
 
}
catch
{
    $ExceptionMessage = "Error in Line: " + $_.Exception.Line + ". " + $_.Exception.GetType().FullName + ": " + $_.Exception.Message + " Stacktrace: " + $_.Exception.StackTrace
    $ExceptionMessage
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial