Skip to content

Instantly share code, notes, and snippets.

@rodolfofadino
Created September 10, 2013 16:41
Show Gist options
  • Save rodolfofadino/6512113 to your computer and use it in GitHub Desktop.
Save rodolfofadino/6512113 to your computer and use it in GitHub Desktop.
Web server powershell
# --------------------------------------------------------------------
# Checking Execution Policy
# --------------------------------------------------------------------
#$Policy = "Unrestricted"
$Policy = "RemoteSigned"
If ((get-ExecutionPolicy) -ne $Policy) {
Write-Host "Script Execution is disabled. Enabling it now"
Set-ExecutionPolicy $Policy -Force
Write-Host "Please Re-Run this script in a new powershell enviroment"
Exit
}
# --------------------------------------------------------------------
# Define the variables.
# --------------------------------------------------------------------
$InetPubRoot = "C:\Inetpub"
$InetPubLog = "C:\Inetpub\Log"
$InetPubWWWRoot = "C:\Inetpub\WWWRoot"
# --------------------------------------------------------------------
# Loading Feature Installation Modules
# --------------------------------------------------------------------
Import-Module ServerManager
# --------------------------------------------------------------------
# Installing IIS
# --------------------------------------------------------------------
Add-WindowsFeature -Name Web-Common-Http,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Http-Logging,Web-Request-Monitor,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Performance,Web-Mgmt-Console,Web-Mgmt-Compat,RSAT-Web-Server,WAS -IncludeAllSubFeature
# --------------------------------------------------------------------
# Loading IIS Modules
# --------------------------------------------------------------------
Import-Module WebAdministration
# --------------------------------------------------------------------
# Creating IIS Folder Structure
# --------------------------------------------------------------------
New-Item -Path $InetPubRoot -type directory -Force -ErrorAction SilentlyContinue
New-Item -Path $InetPubLog -type directory -Force -ErrorAction SilentlyContinue
New-Item -Path $InetPubWWWRoot -type directory -Force -ErrorAction SilentlyContinue
# --------------------------------------------------------------------
# Copying old WWW Root data to new folder
# --------------------------------------------------------------------
$InetPubOldLocation = @(get-website)[0].physicalPath.ToString()
$InetPubOldLocation = $InetPubOldLocation.Replace("%SystemDrive%",$env:SystemDrive)
Copy-Item -Path $InetPubOldLocation -Destination $InetPubRoot -Force -Recurse
# --------------------------------------------------------------------
# Setting directory access
# --------------------------------------------------------------------
$Command = "icacls $InetPubWWWRoot /grant BUILTIN\IIS_IUSRS:(OI)(CI)(RX) BUILTIN\Users:(OI)(CI)(RX)"
cmd.exe /c $Command
$Command = "icacls $InetPubLog /grant ""NT SERVICE\TrustedInstaller"":(OI)(CI)(F)"
cmd.exe /c $Command
# --------------------------------------------------------------------
# Setting IIS Variables
# --------------------------------------------------------------------
#Changing Log Location
$Command = "%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/sites -siteDefaults.logfile.directory:$InetPubLog"
cmd.exe /c $Command
$Command = "%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/log -centralBinaryLogFile.directory:$InetPubLog"
cmd.exe /c $Command
$Command = "%windir%\system32\inetsrv\appcmd set config -section:system.applicationHost/log -centralW3CLogFile.directory:$InetPubLog"
cmd.exe /c $Command
#Changing the Default Website location
Set-ItemProperty 'IIS:\Sites\Default Web Site' -name physicalPath -value $InetPubWWWRoot
# --------------------------------------------------------------------
# Checking to prevent common errors
# --------------------------------------------------------------------
If (!(Test-Path "C:\inetpub\temp\apppools")) {
New-Item -Path "C:\inetpub\temp\apppools" -type directory -Force -ErrorAction SilentlyContinue
}
# --------------------------------------------------------------------
# Deleting Old WWWRoot
# --------------------------------------------------------------------
Remove-Item $InetPubOldLocation -Recurse -Force
# --------------------------------------------------------------------
# Resetting IIS
# --------------------------------------------------------------------
$Command = "IISRESET"
Invoke-Expression -Command $Command
##Instaling .net 4.0
((new-object net.webclient).DownloadFile("http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe","dotNetFx40_Full_x86_x64.exe"))
& .\dotNetFx40_Full_x86_x64.exe /q
##Verificar as versões de framework
function Get-Framework-Versions()
{
$installedFrameworks = @()
if(Test-Key "HKLM:\Software\Microsoft\.NETFramework\Policy\v1.0" "3705") { $installedFrameworks += "1.0" }
if(Test-Key "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Install") { $installedFrameworks += "1.1" }
if(Test-Key "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Install") { $installedFrameworks += "2.0" }
if(Test-Key "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "InstallSuccess") { $installedFrameworks += "3.0" }
if(Test-Key "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v3.5" "Install") { $installedFrameworks += "3.5" }
if(Test-Key "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Client" "Install") { $installedFrameworks += "4.0c" }
if(Test-Key "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full" "Install") { $installedFrameworks += "4.0" }
return $installedFrameworks
}
function Test-Key([string]$path, [string]$key)
{
if(!(Test-Path $path)) { return $false }
if ((Get-ItemProperty $path).$key -eq $null) { return $false }
return $true
}
##executar o teste das versões de framework
Get-Framework-Versions
##LIST VERSIONS OF MVC
Get-WmiObject -Class win32_product -Property Name | Where{$_.Name -like "*mvc*"}
((new-object net.webclient).DownloadFile("http://download.microsoft.com/download/7/0/4/704CEB4C-9F42-4962-A2B0-5C84B0682C7A/WebPlatformInstaller_amd64_en-US.msi","WebPlatformInstaller_amd64_en-US.msi"))
& .\WebPlatformInstaller_amd64_en-US.msi /q
#
#& "C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd.exe" /List /ListOption:All
& "C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd.exe" /Install /Products:"MVC2,MVC3,NETFramework4,NETFramework45,WDeploy,PHP54,ASPNET_REGIIS_NET4" /AcceptEula /ForceReboot
& "C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd.exe" /Install /Products:"WDeploy" /AcceptEula /ForceReboot
& "C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd.exe" /Install /Products:"FTP" /AcceptEula /ForceReboot
$Command = "IISRESET"
Invoke-Expression -Command $Command
Add-WindowsFeature -Name Web-Ftp-Server,Web-Ftp-Mgmt-Console -IncludeAllSubFeature
New-WebFtpSite -Name "Default Ftp" -PhysicalPath C:\inetpub -Port 21
$Command = "IISRESET"
Invoke-Expression -Command $Command
Get-ItemProperty IIS:\Sites\"Default Ftp"
Set-ItemProperty IIS:\Sites\"Default Ftp" -Name ftpServer.security.ssl.controlChannelPolicy -Value 0
Set-ItemProperty IIS:\Sites\"Default Ftp" -Name ftpServer.security.ssl.dataChannelPolicy -Value 0
Set-ItemProperty IIS:\Sites\"Default Ftp" -Name ftpServer.security.authentication.basicAuthentication.enabled -Value $true
Import-Module WebAdministration
Add-WebConfiguration -Filter /System.FtpServer/Security/Authorization -Value (@{AccessType="Allow"; Users="Administrator"; Permissions="Read, Write"}) -PSPath IIS: -Location "Default Ftp"
Add-WebConfiguration -filter /system.webServer/directoryBrowse -PSPath 'IIS:\Sites\Default Ftp' -Value true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment