param ( [string]$DomainName = "contoso.com", [string]$SvcUsername = "svc_iis03", [string]$SvcPassword = "Svc1234!" ) $scriptName = $MyInvocation.MyCommand.Name $logFile = "C:\Logs\${scriptName}_log.txt" Start-Transcript -Path $logFile -Append $wwwroot1 = "C:\inetpub\wwwroot" $wwwroot2 = "C:\inetpub\wwwroot2" try { Install-WindowsFeature -Name Web-Server -IncludeManagementTools Install-WindowsFeature -Name Web-Asp-Net45 New-WebSite -Name "MyASPXSite" -Port 80 -PhysicalPath "C:\inetpub\wwwroot" -ApplicationPool "DefaultAppPool" Set-ItemProperty "IIS:\AppPools\DefaultAppPool" -Name processModel -Value @{userName="$SvcUsername";password="$SvcPassword";identityType=3} New-NetFirewallRule -DisplayName "HTTP (80)" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow Restart-WebAppPool -Name "DefaultAppPool" Write-Host "[INFO] Created first IIS WebSite, Firewall rule and AppPool" } catch { Write-Host "[ERR] Failed to create first IIS WebSite, Firewall rule and AppPool" } try { $svcIIS03Rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$DomainName\$SvcUsername", "Modify", "ContainerInherit, ObjectInherit", "None", "Allow") $acl = Get-Acl $wwwroot1 $acl.SetAccessRule($svcIIS03Rule) Set-Acl -Path $wwwroot1 -AclObject $acl Write-Host "[INFO] Set ACL for $wwwroot1" } catch { Write-Host "[ERR] Failed to set ACL for $wwwroot1" } @" using System; using System.IO; using System.Web.UI; public partial class UploadPage : Page { protected void UploadFile(object sender, EventArgs e) { if (fileUpload.PostedFile != null && fileUpload.PostedFile.ContentLength > 0) { try { string filename = Path.GetFileName(fileUpload.PostedFile.FileName); fileUpload.PostedFile.SaveAs(Server.MapPath(filename)); lblMessage.Text = "File uploaded successfully!"; } catch (Exception ex) { lblMessage.Text = "Error: " + ex.Message; } } else { lblMessage.Text = "Please select a file to upload."; } } } "@ | Out-File C:\inetpub\wwwroot\upload.aspx.cs @" <%@ Page Language="C#" AutoEventWireup="true" CodeFile="upload.aspx.cs" Inherits="UploadPage" %>