search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Hosting & IIS7, Windows Powershell | No Comment | 4,579 views | 16/12/2010 22:24

Powershell function to suspend a IIS7 website.

1
2
3
4
5
6
Function Suspend-WebSite
{
Param ($Description, $Status, $Redirect)
 
    Set-WebConfiguration -Filter /System.WebServer/HttpRedirect -value (@{Enabled="$Status"; Destination="$Redirect"}) -PSPath IIS:\ -Location $Description
}

Status can be true (1) or false (0).


Posted in Hosting & IIS7, Windows Powershell | No Comment | 6,401 views | 16/12/2010 22:21

Powershell function to modify http errors in IIS7.

Function Modify-HttpErrors
{
Param ($Description, $StatusCode, $Path, $ResponseMode, $Action)
 
    If ($Action -eq "Add")
    {
        Set-WebConfiguration -Filter /System.WebServer/HttpErrors/Error[@StatusCode=$StatusCode] -Value @{PrefixLanguageFilePath="$Null"; Path="$Path"; ResponseMode="$ResponseMode"} -PSPath IIS:\ -Location $Description
    }
 
    If ($Action -eq "Remove")
    {
    	Set-WebConfiguration -Filter /System.WebServer/HttpErrors/Error[@StatusCode=$StatusCode] -Value @{PrefixLanguageFilePath="%SystemDrive%\inetpub\custerr"; Path="$StatusCode.html"; ResponseMode="File"} -PSPath IIS:\ -Location $Description
    }
 
    If ($Action -eq "Restore")
    {
    	Clear-WebConfiguration -Filter /System.WebServer/HttpErrors/Error -PSPath IIS:\ -Location $Description
    }
}

StatusCode is the code name of error page, like 404.


Posted in Hosting & IIS7, Windows Powershell | No Comment | 3,938 views | 16/12/2010 22:16

Powershell function to set ReadOnly FTP in IIS7.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Function Set-ReadOnlyFTP
{
Param ($FTPUsername, $ACLRule, $Path)
 
    If ($ACLRule -eq "ReadOnly")
    {
	    $Account = New-Object System.Security.Principal.NtAccount("$FTPUsername")
	    $ACL = Get-Acl -Path "$Path"
	    $Permission = "$Account","ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow"
	    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
	    $ACL.SetAccessRule($AccessRule)
            $ACL | Set-Acl "$Path"
    }
 
    If ($ACLRule -eq "Modify")
    {
	    $Account = New-Object System.Security.Principal.NtAccount("$FTPUsername")
	    $ACL = Get-Acl -Path "$Path"
	    $Permission = "$Account","Modify","ContainerInherit,ObjectInherit","None","Allow"
	    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
	    $ACL.SetAccessRule($AccessRule)
            $ACL | Set-Acl "$Path"
    }
}

I won’t explain arguments because they are clear to understand.


Posted in Hosting & IIS7, Windows Powershell | No Comment | 3,864 views | 16/12/2010 22:13

Advanced Directory ACL Powershell function for IIS7.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Function Set-DirACL
{
Param ($IUSRName, $Username, $Password, $ListRule, $Path, $ACLRule, $Description, $Directory)
 
    If ((Test-Path -Path $Path) -ne $True) 
    { 
        New-Item $Path -Type Directory
    }
 
    If ($ACLRule -eq "ReadAndExecute")
    {
	    $Account = New-Object System.Security.Principal.NtAccount("$IUSRName")
	    $ACL = Get-Acl -Path "$Path"
	    $Permission = "$Account","ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow"
	    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
	    $ACL.SetAccessRule($AccessRule)
            $ACL | Set-Acl "$Path"
    }
 
    If ($ACLRule -eq "Modify")
    {
	    $Account = New-Object System.Security.Principal.NtAccount("$IUSRName")
	    $ACL = Get-Acl -Path "$Path"
	    $Permission = "$Account","Modify","ContainerInherit,ObjectInherit","None","Allow"
	    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
	    $ACL.SetAccessRule($AccessRule)
            $ACL | Set-Acl "$Path"
    }
 
    If ($ListRule -eq "ListFolders")
    {
           Set-WebConfigurationProperty System.WebServer/DirectoryBrowse IIS:\Sites\$Description\$Directory -Name Enabled -Value True
    }
 
    If ($ListRule -eq "NotListFolders")
    {
           Set-WebConfigurationProperty System.WebServer/DirectoryBrowse IIS:\Sites\$Description\$Directory -Name Enabled -Value False
    }
}

I won’t explain arguments because they are clear to understand.


Posted in Hosting & IIS7, Windows Powershell | No Comment | 4,527 views | 16/12/2010 22:07

Powershell function to removing bindings from websites in IIS7.

1
2
3
4
5
6
Function Remove-Binding
{
Param ($Description, $Binding)
 
	Remove-WebBinding -Name $Description -BindingInformation *:80:$Binding
}

Description is the name of website in IIS7.


Posted in Hosting & IIS7, Windows Powershell | No Comment | 5,464 views | 16/12/2010 22:05

Simple Powershell function to add new binding to IIS7 Websites.

1
2
3
4
5
6
Function Add-Binding
{
Param ($Description, $Binding)
 
	New-ItemProperty IIS:\Sites\$Description -Name Bindings -Value @{Protocol="http";BindingInformation="*:80:$Binding"}
}

Description is the name of website in IIS7.


Posted in Hosting & IIS7, Windows Powershell | 1 Comment | 5,459 views | 16/12/2010 22:00

Powershell function to setting basic authentication for websites in IIS7.

1
2
3
4
5
6
7
Function Set-UserPermissions
{
Param ($Description, $Username, $Password)
 
	Set-ItemProperty IIS:\Sites\$Description -Name Username -Value "$Username"
	Set-ItemProperty IIS:\Sites\$Description -Name Password -Value "$Password"
}

Description is the name of website in IIS7.