PowerShell Windows 2012 R2 IIS FTP web user creation

( if you want FTP folder isolation for local users on  Windows Server 2012 r2 Setup read : https://community.rackspace.com/products/f/25/t/491

Windows 2012 r2 PowerShell Task: Uses PowerShell

  LOCAL USER CREATION TASKS
    • PowerShell Create Local user account
    • PowerShell Set description on account to reflect day activated
    • PowerShell  Set Password to never expire / user cant change password
    • PowerShell Create  IIS website VirtualDirectory  IIS:\Sites\ (IIS 7, IIS 7.5
    • PowerShell Create  users folder in FTProot IIS
    • PowerShell Create FTP directory IIS
    • PowerShell Create user permissions ACL  ( Adds user to folder / Access = modify)
    •  PowerShell Create local group membership to FTP Group
  • PowerShell  use Web Administration module
    #########################
    # #windows 2012 R2 create FTP 2012r2, IIS 2012 R2
    # Description:www.BrilliantlyEasy.com import
    # Create local users for FTP
    # ######## Create HTML URL Links
    # Add user to local FTP #
    # Make edies to someUser,SomePassword,SomeComputer
    #####################################<
    Import-Module WebAdministration
    Write-Host -foregroundcolor Yellow 'Admin Privileges Required!'
    #create local user
    $accountName = 'someUser'
    $password = 'somePassword'
    $day = get-date -format "MM.dd.yyyy"
    $description = "$day account activated"
    $computer = [ADSI]"WinNT://$env:computername,computer"
    $user = $computer.Create("user", $accountName)
    $user.SetPassword($password)
    $user.SetInfo()
    $user.Description = $description
    $user.SetInfo()
    $user.userflags = 65536 -bor 64 #user cant change / never expire
    $user.SetInfo()
    $ServerName = 'someComputerName'
    $group = [ADSI]"WinNT://$ServerName/FTP USER"
    $group.add("WinNT://$ServerName/$accountName") ;
    #END create local user
     #create users web directory publish folder
    New-Item -path C:\inetpub\ftproot\Localuser `
    -name $accountName -type directory
    Start-Sleep -Seconds 3
    New-Item "IIS:\Sites\Default Web Site\$accountName" `
    -type VirtualDirectory -physicalPath C:\inetpub\ftproot\Localuser\$accountName
    
     #this function sets access rules for user
    Function Acl-Rule
    {
    #target folder that needs security rules added
    $target = "C:\inetpub\ftproot\Localuser\" + $accountName
    $mydir = get-acl $target
    #allow the proper account Modify control from $account
    $rule = new-object system.security.accesscontrol.filesystemaccessrule`
     ($accountName,"Modify", "containerinherit,objectinherit","none","allow")
    #Add the access rule to be applied later
    $mydir.addaccessrule($rule)
    #}
    #apply all access rules to target directory
    set-acl $target $mydir
     }#end function
    
     Acl-Rule
     }
    #END

share with friends

Share to Google Buzz
Share to Google Plus
Share to LiveJournal
Share to Odnoklassniki

One Response to PowerShell Windows 2012 R2 IIS FTP web user creation

  1. reiju November 25, 2016 at 10:14 am #

    Its not working for me :/

Leave a Reply