Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Hosting & IIS7, Windows Powershell | No Comment | 4,640 views | 16/12/2010 22:35
Powershell function to remove IIS7 FTP.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| Function Remove-FTPSite
{
Param ($FTPUsername, $LogDir)
If ($FTPUsername -eq $null)
{
Write-Host FTP Username is null
}
Else
{
$FTPUsername = ($FTPUsername.Split("\")[1])
Remove-Item IIS:\Sites\".Default FTP Site"\$FTPUserDir\$FTPUsername -Recurse
}
} |
Function Remove-FTPSite
{
Param ($FTPUsername, $LogDir)
If ($FTPUsername -eq $null)
{
Write-Host FTP Username is null
}
Else
{
$FTPUsername = ($FTPUsername.Split("\")[1])
Remove-Item IIS:\Sites\".Default FTP Site"\$FTPUserDir\$FTPUsername -Recurse
}
}
I did split FTP Username for domain environments.
Posted in Hosting & IIS7, Windows Powershell | No Comment | 8,717 views | 16/12/2010 22:30
Powershell function to remove IIS7 Application Pools.
1
2
3
4
5
6
| Function Remove-AppPool
{
Param ($AppPool)
Remove-Item IIS:\AppPools\$AppPool -Recurse
} |
Function Remove-AppPool
{
Param ($AppPool)
Remove-Item IIS:\AppPools\$AppPool -Recurse
}
AppPool is the name of the Application Pool.
Posted in Hosting & IIS7, Windows Powershell | No Comment | 5,365 views | 16/12/2010 22:29
Powershell function to remove IIS7 websites.
Function Remove-WebSite
{
Param ($Description)
Remove-Item IIS:\Sites\$Description -Recurse
} |
Function Remove-WebSite
{
Param ($Description)
Remove-Item IIS:\Sites\$Description -Recurse
}
Description is the name of website in IIS7.
Posted in Hosting & IIS7, Windows Powershell | No Comment | 4,494 views | 16/12/2010 22:26
Powershell function to set W3C logging to IIS7 websites.
1
2
3
4
5
6
| Function Set-W3CLogging
{
Param ($LogDir, $Description)
Set-ItemProperty IIS:\Sites\$Description -Name LogFile.Directory -Value "$LogDir"
} |
Function Set-W3CLogging
{
Param ($LogDir, $Description)
Set-ItemProperty IIS:\Sites\$Description -Name LogFile.Directory -Value "$LogDir"
}
LogDir is the path of Log directory.
Posted in Hosting & IIS7, Windows Powershell | No Comment | 4,580 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
} |
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,413 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
}
} |
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,942 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"
}
} |
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.
|