Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Hosting & IIS7, Windows Powershell | 1 Comment | 7,133 views | 16/12/2010 21:49
Powershell function to create a new application pool in IIS7.
1
2
3
4
5
6
7
8
9
10
11
| Function Create-AppPool
{
Param ($AppPool, $Username, $Password)
New-Item IIS:\AppPools\$AppPool
$NewPool = Get-Item IIS:\AppPools\$AppPool
$NewPool.ProcessModel.Username = "$Username"
$NewPool.ProcessModel.Password = "$Password"
$NewPool.ProcessModel.IdentityType = 3
$NewPool | Set-Item
} |
Function Create-AppPool
{
Param ($AppPool, $Username, $Password)
New-Item IIS:\AppPools\$AppPool
$NewPool = Get-Item IIS:\AppPools\$AppPool
$NewPool.ProcessModel.Username = "$Username"
$NewPool.ProcessModel.Password = "$Password"
$NewPool.ProcessModel.IdentityType = 3
$NewPool | Set-Item
}
You can set IdentityType for Network Service. Please check Technet for IdentityTypes.
Posted in Hosting & IIS7, Windows Powershell | 1 Comment | 9,157 views | 16/12/2010 21:45
Powershell function to modify Default Document configuration in IIS7.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| Function Modify-DefaultDoc
{
Param ($Description, $DefaultDocName, $Action)
If ($Action -eq "Add")
{
Add-WebConfiguration //DefaultDocument/Files -AtIndex 0 -Value @{Value="$DefaultDocName"} -PSPath IIS:\ -Location $Description
}
If ($Action -eq "Remove")
{
Clear-WebConfiguration //DefaultDocument/Files -PSPath IIS:\ -Location $Description
}
} |
Function Modify-DefaultDoc
{
Param ($Description, $DefaultDocName, $Action)
If ($Action -eq "Add")
{
Add-WebConfiguration //DefaultDocument/Files -AtIndex 0 -Value @{Value="$DefaultDocName"} -PSPath IIS:\ -Location $Description
}
If ($Action -eq "Remove")
{
Clear-WebConfiguration //DefaultDocument/Files -PSPath IIS:\ -Location $Description
}
}
If you want to modify list, just change -AtIndex position.
Posted in Hosting & IIS7, Windows Powershell | No Comment | 3,035 views | 11/12/2010 01:31
Simple script to modify IIS7 FTP Quota with Powershell.
1
2
3
4
5
6
| Function Modify-FTPQuota
{
Param ($LogDir, $FTPQuota)
DirQuota Quota Modify /Path:"$LogDir" /Limit:$FTPQuota
} |
Function Modify-FTPQuota
{
Param ($LogDir, $FTPQuota)
DirQuota Quota Modify /Path:"$LogDir" /Limit:$FTPQuota
}
DirQuota command comes with File Services feature in Windows Server 2008 to limit directories.
Posted in Hosting & IIS7, Windows Powershell | No Comment | 15,507 views | 11/12/2010 01:28
Detailed script about how to create IIS7 ftp site with Powershell.
1
2
3
4
5
6
7
8
9
10
| Function Create-FTPSite
{
Param ($FTPUsername, $LogDir, $FTPQuota, $FTPUserDir)
$FTPUserPath = ($FTPUsername.Split("\")[1])
New-Item IIS:\Sites\".Default FTP Site"\$FTPUserDir\$FTPUserPath -Type VirtualDirectory -PhysicalPath "$LogDir"
Add-WebConfiguration -Filter /System.FtpServer/Security/Authorization -Value (@{AccessType="Allow"; Users="$FTPUserPath"; Permissions="Read, Write"}) -PSPath IIS: -Location ".Default FTP Site/$FTPUserDir/$FTPUserPath"
Clear-WebConfiguration -Filter /System.FtpServer/Security/Authorization -PSPath IIS: -Location ".Default FTP Site/$FTPUserDir"
DirQuota Quota Add /Path:"$LogDir" /Limit:$FTPQuota
} |
Function Create-FTPSite
{
Param ($FTPUsername, $LogDir, $FTPQuota, $FTPUserDir)
$FTPUserPath = ($FTPUsername.Split("\")[1])
New-Item IIS:\Sites\".Default FTP Site"\$FTPUserDir\$FTPUserPath -Type VirtualDirectory -PhysicalPath "$LogDir"
Add-WebConfiguration -Filter /System.FtpServer/Security/Authorization -Value (@{AccessType="Allow"; Users="$FTPUserPath"; Permissions="Read, Write"}) -PSPath IIS: -Location ".Default FTP Site/$FTPUserDir/$FTPUserPath"
Clear-WebConfiguration -Filter /System.FtpServer/Security/Authorization -PSPath IIS: -Location ".Default FTP Site/$FTPUserDir"
DirQuota Quota Add /Path:"$LogDir" /Limit:$FTPQuota
}
DirQuota command comes with File Services feature in Windows Server 2008 to limit directories.
Posted in Hosting & IIS7, Windows Powershell | 4 Comments | 11,528 views | 11/12/2010 01:25
Detailed script about how to create website in IIS7 with Powershell.
1
2
3
4
5
6
7
| Function Create-WebSite
{
Param ($LogDir, $Description, $Domain)
$Domain = ($Domain.TrimStart("www")).TrimStart(".")
New-Item IIS:\Sites\$Description -Bindings (@{Protocol="http";BindingInformation="*:80:$Domain"},@{Protocol="http";BindingInformation="*:80:www.$Domain"}) -PhysicalPath "$LogDir\http"
} |
Function Create-WebSite
{
Param ($LogDir, $Description, $Domain)
$Domain = ($Domain.TrimStart("www")).TrimStart(".")
New-Item IIS:\Sites\$Description -Bindings (@{Protocol="http";BindingInformation="*:80:$Domain"},@{Protocol="http";BindingInformation="*:80:www.$Domain"}) -PhysicalPath "$LogDir\http"
}
$LogDir is the path of FTP directory and $Description is the name of the website.
Posted in Hosting & IIS7, Windows Powershell | No Comment | 2,309 views | 11/12/2010 01:22
One of my script about how to set ACL for FTP users.
1
2
3
4
5
6
7
8
9
10
11
12
| Function Set-FTPACL
{
Param ($FTPUsername, $LogDir)
$Account = New-Object System.Security.Principal.Ntaccount("$FTPUsername")
$Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
$ACL = Get-Acl -Path "$LogDir"
$Permission = "$Account","Modify","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl "$LogDir"
} |
Function Set-FTPACL
{
Param ($FTPUsername, $LogDir)
$Account = New-Object System.Security.Principal.Ntaccount("$FTPUsername")
$Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
$ACL = Get-Acl -Path "$LogDir"
$Permission = "$Account","Modify","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl "$LogDir"
}
$LogDir is the path of FTP directory.
Posted in Hosting & IIS7, Windows Powershell | No Comment | 2,814 views | 11/12/2010 01:18
Very detailed script about how to set ACL for IIS users.
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
| Function Set-IISACL
{
Param ($Username, $LogDir)
$Account = New-Object System.Security.Principal.Ntaccount("$Username")
$Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
$ACL = Get-Acl -Path "$LogDir"
$ACL.SetAccessRuleProtection($True, $True)
Set-Acl -Path "$LogDir" -AclObject $ACL
$Permission = "$Account","ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl "$LogDir"
$Account = New-Object System.Security.Principal.Ntaccount("$Username")
$Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
$ACL = Get-Acl -Path "$LogDir\db"
$Permission = "$Account","Modify","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl "$LogDir\db"
$Account = New-Object System.Security.Principal.Ntaccount("$Username")
$Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
$ACL = Get-Acl -Path "$LogDir\http\upload"
$Permission = "$Account","modify","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl "$LogDir\http\upload"
} |
Function Set-IISACL
{
Param ($Username, $LogDir)
$Account = New-Object System.Security.Principal.Ntaccount("$Username")
$Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
$ACL = Get-Acl -Path "$LogDir"
$ACL.SetAccessRuleProtection($True, $True)
Set-Acl -Path "$LogDir" -AclObject $ACL
$Permission = "$Account","ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl "$LogDir"
$Account = New-Object System.Security.Principal.Ntaccount("$Username")
$Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
$ACL = Get-Acl -Path "$LogDir\db"
$Permission = "$Account","Modify","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl "$LogDir\db"
$Account = New-Object System.Security.Principal.Ntaccount("$Username")
$Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
$ACL = Get-Acl -Path "$LogDir\http\upload"
$Permission = "$Account","modify","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl "$LogDir\http\upload"
}
Contains example for Modify and Read Only permissions.
|