Setting “Password never expires” for Active Directory Users with Powershell

March 2nd, 2010 admin Posted in Hosting & IIS7, Windows Powershell, Windows Server 1 Comment »

You have to set “Password never expires” for some active directory users like IIS or SCVMM users. To do this with Powershell, we’ll simply use “userAccountControl” property with Powershell.

1
2
3
$User = [ADSI] "LDAP://CN=$Username,$CustomerOU,$FQDN"
$User.Put("userAccountControl", "65536")
$User.SetInfo()

65536 means “Password never expires”. Be careful with LDAP name.

AddThis Social Bookmark Button

Checking Active Directory User with Powershell

March 2nd, 2010 admin Posted in Hosting & IIS7, Windows Powershell, Windows Server No Comments »

This is another way to check active directory user with Powershell. I made a function.

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
Function Check-ADUser
{
Param ($Username)
 
    $ADRoot = [ADSI]''
    $ADSearch = New-Object System.DirectoryServices.DirectorySearcher($ADRoot) 
    $SAMAccountName = "$Username"
    $ADSearch.Filter = "(&(objectClass=user)(sAMAccountName=$SAMAccountName))"
    $Result = $ADSearch.FindAll()
 
    If($Result.Count -eq 0)
    {
        Write-Host "No such user on the Server" | Out-Null
        $Status = "0"
    }
    Else
    {
        Write-Host "User exist on the Server" | Out-Null
        $Status = "1"
    }
 
    $Results = New-Object Psobject
    $Results | Add-Member Noteproperty Status $Status
    Write-Output $Results    
}

Usage:

Check-ADUser -Username "yusufozturk"

You can use this function with Status property. It’s useful.

AddThis Social Bookmark Button

Creating a Quota Limit for IIS7.5 FTP Sites with Powershell

February 27th, 2010 admin Posted in Hosting & IIS7, Windows Powershell, Windows Server No Comments »

You should install Windows File Services to use DirQuota cmdlet in Powershell.

DirQuota Quota Add /Path:"$LogDir" /Limit:$FTPQuota

Usage of $FTPQuota is like “100mb”. You can use help to find out more.

AddThis Social Bookmark Button

Clearing Default Security Settings of FTP on IIS7.5 with Powershell

February 27th, 2010 admin Posted in Hosting & IIS7, Windows Powershell, Windows Server No Comments »

First you need to clear default security settings to create your own settings.

Clear-WebConfiguration -Filter /System.FtpServer/Security/Authorization -PSPath IIS: -Location "Default FTP Site/$FTPUserDir"

As I said in earlier posts, $FTPUserDir is the name of the FTP Virtual Site.

AddThis Social Bookmark Button

Setting FTP Server Authorization with Powershell on IIS7.5

February 27th, 2010 admin Posted in Hosting & IIS7, Windows Powershell, Windows Server 1 Comment »

Last post, We created a new ftp site on IIS7.5 with Powershell.
Now we set security settings of FTP site with Powershell.

Import-Module WebAdministration
Add-WebConfiguration -Filter /System.FtpServer/Security/Authorization -Value (@{AccessType="Allow"; Users="$FTPUsername"; Permissions="Read, Write"}) -PSPath IIS: -Location "Default FTP Site/$FTPUserDir/$FTPUsername"

My purpose is showing you how to use Powershell to do your works easy. Not explaining IIS7 FTP settings. If you have questions about Security settings of IIS7.5, please mail me. I’m trying to reply all user mails.

AddThis Social Bookmark Button

Creating a New Web FTP Site on IIS7.5 with Powershell

February 27th, 2010 admin Posted in Hosting & IIS7, Windows Powershell, Windows Server No Comments »

It’s really easy to create new ftp web site on IIS7.5 with Powershell WebAdministration module.

Import-Module WebAdministration
New-Item IIS:\Sites\"Default FTP Site"\$FTPUserDir\$FTPUsername -Type VirtualDirectory -PhysicalPath "$LogDir"</dir>

$FTPUserDir is the name of the Virtual Directory name. You should use “LocalUser” for standalone machines.

AddThis Social Bookmark Button

Creating a new Web Site on IIS7.5 with a Powershell Function

February 27th, 2010 admin Posted in Hosting & IIS7, Windows Powershell, Windows Server No Comments »

I’ll show you how to create a New Web site on IIS7.5 with a Powershell function.

Function Create-WebSite
{
Param ($LogDir, $Description, $Domain)
 
$Domain = $Domain.TrimStart("www.")
New-Item IIS:\Sites\$Description -Bindings (@{Protocol="http";BindingInformation="*:80:$Domain"},@{Protocol="http";BindingInformation="*:80:www.$Domain"}) -PhysicalPath "$LogDir\http"
}

You can execute our function using with this command:

Create-WebSite -Logdir "C:\inetpub" -Description "My New Web Site" -Domain "www.yusufozturk.info"

That’s easy!

AddThis Social Bookmark Button

Creating a new Web Site on IIS7.5 with Powershell

February 27th, 2010 admin Posted in Hosting & IIS7, Windows Powershell, Windows Server No Comments »

It’s really easy to create new web site on IIS7.5 with Powershell WebAdministration module.

Import-Module WebAdministration
New-Item IIS:\Sites\$Description -Bindings (@{Protocol="http";BindingInformation="*:80:$Domain"},@{Protocol="http";BindingInformation="*:80:www.$Domain"}) -PhysicalPath "$LogDir\http"

As you see, you can set Bindings with the same command. Next time, I’ll write a function.

AddThis Social Bookmark Button

Setting ACL of Web Site directories with a Function on Powershell

February 27th, 2010 admin Posted in Hosting & IIS7, Windows Powershell, Windows Server No Comments »

After creating web site directories, you should set ACL settings of directories.

Function Set-IISACL
{
Param ($Username, $LogDir)
 
$Netbios = "FABRIKAM"
$Account = New-Object System.Security.Principal.Ntaccount("$Netbios\$Username")
$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"
$Permission = "$Account","Modify","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl "$LogDir\db"
$Permission = "$Account","Modify","ContainerInherit,ObjectInherit","None","Allow"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl "$LogDir\http\upload"
}

Fabrikam is my Netbios name. If you create your users on Active Directory, you should write your Netbios name of your domain. But on a local machine, you can use your local computer name like “Plesk01\username”.

AddThis Social Bookmark Button

Creating IIS7.5 Web Site Root Directories with a Function on Powershell

February 27th, 2010 admin Posted in Hosting & IIS7, Windows Powershell, Windows Server No Comments »

You can create default web site directories with a function on Powershell:

Function Create-Directories
{
Param ($LogDir)
 
New-Item "$LogDir" -Type Directory
New-Item "$LogDir\db" -Type Directory
New-Item "$LogDir\http" -Type Directory
New-Item "$LogDir\http\bin" -Type Directory
New-Item "$LogDir\http\stats" -Type Directory
New-Item "$LogDir\http\upload" -Type Directory
}

You can execute our function using with this command:

Create-Directories -LogDir "C:\inetpub"

Have fun!

AddThis Social Bookmark Button