param([ValidateSet('Baseline','Application')][string]$Role)
$ErrorActionPreference='Stop'
New-Item -Path 'HKLM:\SOFTWARE\AzureWorkshopz\MachineConfiguration' -Force|Out-Null
Set-ItemProperty -Path 'HKLM:\SOFTWARE\AzureWorkshopz\MachineConfiguration' -Name Environment -Value Workshop -Type String
Set-ItemProperty -Path 'HKLM:\SOFTWARE\AzureWorkshopz\MachineConfiguration' -Name BaselineVersion -Value '1.1.0' -Type String
Set-NetFirewallProfile -Profile Domain,Private,Public -Enabled True
Disable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol -NoRestart -ErrorAction SilentlyContinue|Out-Null
Set-Service EventLog -StartupType Automatic
Start-Service EventLog
New-Item -ItemType Directory -Path 'C:\AzureWorkshopz\MachineConfiguration' -Force|Out-Null
$content="Azure Workshopz Machine Configuration`r`nBaselineVersion=1.1.0`r`nDesiredState=Compliant`r`n"
Set-Content 'C:\AzureWorkshopz\MachineConfiguration\desired-state.txt' -Value $content -Encoding ascii -NoNewline
if($Role -eq 'Application'){
  Install-WindowsFeature Web-Server -IncludeManagementTools|Out-Null
  New-Item -ItemType Directory 'C:\inetpub\wwwroot' -Force|Out-Null
  Set-Content 'C:\inetpub\wwwroot\index.html' -Value '<html><body><h1>Azure Workshopz</h1><p>Machine Configuration application server proof.</p></body></html>' -Encoding ascii
}else{Remove-WindowsFeature Web-Server -Restart:$false|Out-Null}
if(-not [Diagnostics.EventLog]::SourceExists('AzureWorkshopzMachineConfiguration')){New-EventLog -LogName Application -Source AzureWorkshopzMachineConfiguration}
Write-EventLog -LogName Application -Source AzureWorkshopzMachineConfiguration -EntryType Information -EventId 4100 -Message 'Workshop desired state initialized.'
[pscustomobject]@{Hostname=$env:COMPUTERNAME;Role=$Role;FirewallProfiles=@(Get-NetFirewallProfile|Where-Object Enabled).Count;SMB1=(Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol).State;EventLog=(Get-CimInstance Win32_Service -Filter "Name='EventLog'").StartMode;IIS=[bool](Get-WindowsFeature Web-Server).Installed}
