commit 1808f43f535837153490a5d6abbdc1af1566394b Author: Iwan Clement Date: Tue Nov 3 18:55:20 2020 +0100 first commit diff --git a/Exercise Files/01_02/01_02_begin.ps1 b/Exercise Files/01_02/01_02_begin.ps1 new file mode 100755 index 0000000..d3979e6 --- /dev/null +++ b/Exercise Files/01_02/01_02_begin.ps1 @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + +configuration InstalledRoles +{ + Param([string[]]$ComputerName = "srv01") + Import-DscResource -ModuleName PSDesiredStateConfiguration + Node $ComputerName + { + WindowsFeature HaveBitLocker + { + Ensure = "Present" + Name = "BitLocker" + } + WindowsFeature NoWebServer + { + Ensure = "Absent" + Name = "Web-Server" + } + } +} + diff --git a/Exercise Files/01_02/01_02_end.ps1 b/Exercise Files/01_02/01_02_end.ps1 new file mode 100755 index 0000000..fea14a8 --- /dev/null +++ b/Exercise Files/01_02/01_02_end.ps1 @@ -0,0 +1,48 @@ + +Configuration StopMaps +{ + Import-DscResource -ModuleName PSDesiredStateConfiguration + Node localhost + { + + Service DisableMaps + { + Name = "MapsBroker" + StartupType = "Disabled" + State = "Stopped" + } + } +} + + + + + + + + + + + + + + +configuration InstalledRoles +{ + Param([string[]]$ComputerName = "srv01") + Import-DscResource -ModuleName PSDesiredStateConfiguration + Node $ComputerName + { + WindowsFeature HaveBitLocker + { + Ensure = "Present" + Name = "BitLocker" + } + WindowsFeature NoWebServer + { + Ensure = "Absent" + Name = "Web-Server" + } + } +} + diff --git a/Exercise Files/01_03/01_03_begin.ps1 b/Exercise Files/01_03/01_03_begin.ps1 new file mode 100755 index 0000000..d4cb00a --- /dev/null +++ b/Exercise Files/01_03/01_03_begin.ps1 @@ -0,0 +1,36 @@ + +Configuration StopMaps +{ + Import-DscResource -ModuleName PSDesiredStateConfiguration + Node localhost + { + + Service DisableMaps + { + Name = "MapsBroker" + StartupType = "Disabled" + State = "Stopped" + } + } +} + + +Configuration InstalledRoles +{ + Param([string[]]$ComputerName = "srv01") + Import-DscResource -ModuleName PSDesiredStateConfiguration + Node $ComputerName + { + WindowsFeature HaveBitLocker + { + Ensure = "Present" + Name = "BitLocker" + } + WindowsFeature NoWebServer + { + Ensure = "Absent" + Name = "Web-Server" + } + } +} + diff --git a/Exercise Files/01_04/01_04.ps1 b/Exercise Files/01_04/01_04.ps1 new file mode 100755 index 0000000..de23023 --- /dev/null +++ b/Exercise Files/01_04/01_04.ps1 @@ -0,0 +1,54 @@ +Install-Module xSmbShare + +Install-Module cNtfsAccessControl + +Configuration SMBPull +{ + Import-DscResource -ModuleName PSDesiredStateConfiguration + Import-DscResource -ModuleName xSmbShare + Import-DscResource -ModuleName cNtfsAccessControl + + Node localhost + { + + File CreateFolder + { + DestinationPath = 'C:\DSCSMB' + Type = 'Directory' + Ensure = 'Present' + } + + xSMBShare CreateShare + { + Name = 'DscSmbPull' + Path = 'C:\DSCSMB' + FullAccess = 'landonhotel\administrator' + ReadAccess = 'landonhotel\srv02$' + FolderEnumerationMode = 'AccessBased' + Ensure = 'Present' + DependsOn = '[File]CreateFolder' + } + + cNtfsPermissionEntry PermissionSet1 + { + Ensure = 'Present' + Path = 'C:\DSCSMB' + Principal = 'landonhotel\srv02$' + AccessControlInformation = @( + cNtfsAccessControlInformation + { + AccessControlType = 'Allow' + FileSystemRights = 'ReadAndExecute' + Inheritance = 'ThisFolderSubfoldersAndFiles' + NoPropagateInherit = $false + } + ) + DependsOn = '[File]CreateFolder' + } + } +} + +SmbPull + +Start-DscConfiguration -Path SmbPull -Wait -Verbose + diff --git a/Exercise Files/01_05/01_05.ps1 b/Exercise Files/01_05/01_05.ps1 new file mode 100755 index 0000000..91ffef3 --- /dev/null +++ b/Exercise Files/01_05/01_05.ps1 @@ -0,0 +1,34 @@ +New-Guid + + +Configuration ConfiguredServer +{ + Param([string[]]$ComputerName = "srv02") + Import-DscResource -ModuleName PSDesiredStateConfiguration + Node $ComputerName + { + Service NoMapsDownload + { + Name = "MapsBroker" + StartupType = "Disabled" + State = "Stopped" + } + Service HaveBITS + { + Name = "BITS" + StartupType = "Automatic" + State = "Running" + } + WindowsFeature NoWebServer + { + Ensure = "Absent" + Name = "Web-Server" + } + } +} + + + +ConfiguredServer + +New-DscChecksum -Path .\ConfiguredServer\ #Place .mof filename here diff --git a/Exercise Files/01_06/01_06.ps1 b/Exercise Files/01_06/01_06.ps1 new file mode 100755 index 0000000..7cba5ea --- /dev/null +++ b/Exercise Files/01_06/01_06.ps1 @@ -0,0 +1,29 @@ +# GUID copied and pasted from SMB pull server +# Paste GID here + + +[DSCLocalConfigurationManager()] +Configuration PullClientConfigID +{ + Node localhost + { + Settings + { + RefreshMode = 'Pull' + ConfigurationID = '#paste GID here' + RefreshFrequencyMins = 30 + RebootNodeIfNeeded = $true + # ConfigurationMode = 'ApplyAndMonitor' --or-- 'ApplyAndAutoCorrect' + } + ConfigurationRepositoryShare SMBPullServer + { + SourcePath = '\\srv01\DscSmbPull' + + } + } +} + +PullClientConfigID + +Set-DscLocalConfigurationManager -ComputerName localhost -Path .\PullClientConfigID + diff --git a/Exercise Files/02_03/02_03.ps1 b/Exercise Files/02_03/02_03.ps1 new file mode 100755 index 0000000..b2536fa --- /dev/null +++ b/Exercise Files/02_03/02_03.ps1 @@ -0,0 +1,22 @@ +New-PSRoleCapabilityFile -Path C:\JEA\TechJEARole.psrc + + + + + +# Create a folder in the local modules path for thismodule +$Srv1ModulePath = Join-Path $env:ProgramFiles "WindowsPowerShell\Modules\LandonHotelJEA" +New-Item -ItemType Directory -Path $Srv1ModulePath + + + +# Create an empty module and manifest. +New-Item -ItemType File -Path (Join-Path $Srv1ModulePath "LHJEATechSupport.psm1") +New-ModuleManifest -Path (Join-Path $Srv1ModulePath "LandonHotelJEA.psd1") -RootModule "LHJEATechSupport.psm1" + + + +# Create the RoleCapabilities folder and copy the PSRC file to it +$RoleCapFolder = Join-Path $Srv1ModulePath "RoleCapabilities" +New-Item -ItemType Directory $RoleCapFolder +Copy-Item -Path C:\Scripts\TechJEARole.psrc -Destination $RoleCapFolder \ No newline at end of file diff --git a/Exercise Files/02_04/02_04.ps1 b/Exercise Files/02_04/02_04.ps1 new file mode 100755 index 0000000..2747a3a --- /dev/null +++ b/Exercise Files/02_04/02_04.ps1 @@ -0,0 +1,9 @@ + +New-PSSessionConfigurationFile -SessionType RestrictedRemoteServer -Path C:\JEA\JEAEndpoint1.pssc + + + + + +Test-PSSessionConfigurationFile -Path C:\JEA\JEAEndpoint1.pssc # should yield True + diff --git a/Exercise Files/03_03/03_03.ps1 b/Exercise Files/03_03/03_03.ps1 new file mode 100755 index 0000000..f180976 --- /dev/null +++ b/Exercise Files/03_03/03_03.ps1 @@ -0,0 +1,62 @@ +Import-Module LandonHotelAD +Import-Module LHExchange + +Add-Type -AssemblyName System.Windows.Forms +Add-Type -AssemblyName System.Drawing + +$AdmissionsAccount = New-Object System.Windows.Forms.Form + $AdmissionsAccount.Text = "Create a New Account" + $AdmissionsAccount.Size = New-Object System.Drawing.Size(300,300) + $AdmissionsAccount.MaximizeBox = $false + $AdmissionsAccount.MinimizeBox = $false + $AdmissionsAccount.ControlBox = $true + +$TextBox_FName = New-Object System.Windows.Forms.TextBox + $TextBox_FName.Location = New-Object System.Drawing.Size(25,40) + $TextBox_FName.Size = New-Object System.Drawing.Size(250,20) + $TextBox_FName.Text = "First Name" + $AdmissionsAccount.Controls.Add($TextBox_FName) + +$TextBox_LName = New-Object System.Windows.Forms.TextBox + $TextBox_LName.Location = New-Object System.Drawing.Size(25,70) + $TextBox_LName.Size = New-Object System.Drawing.Size(250,20) + $TextBox_LName.Text = "Last Name" + $AdmissionsAccount.Controls.Add($TextBox_LName) + +$TextBox_UName = New-Object System.Windows.Forms.TextBox + $TextBox_UName.Location = New-Object System.Drawing.Size(25,100) + $TextBox_UName.Size = New-Object System.Drawing.Size(250,20) + $TextBox_UName.Text = "User Name" + $AdmissionsAccount.Controls.Add($TextBox_UName) + +$TextBox_Job = New-Object System.Windows.Forms.TextBox + $TextBox_Job.Location = New-Object System.Drawing.Size(25,130) + $TextBox_Job.Size = New-Object System.Drawing.Size(250,20) + $TextBox_Job.Text = "Job Title" + $AdmissionsAccount.Controls.Add($TextBox_Job) + +$TextBox_EmID = New-Object System.Windows.Forms.TextBox + $TextBox_EmID.Location = New-Object System.Drawing.Size(25,160) + $TextBox_EmID.Size = New-Object System.Drawing.Size(250,20) + $TextBox_EmID.Text = "Employee ID" + $AdmissionsAccount.Controls.Add($TextBox_EmID) + +$Button_Close = New-Object System.Windows.Forms.Button + $Button_Close.Location = New-Object System.Drawing.Size(25,200) + $Button_Close.Size = New-Object System.Drawing.Size(120,25) + $Button_Close.TextAlign = "MiddleCenter" + $Button_Close.Text = "Create User Account" + $Button_Close.Add_Click({$AdmissionsAccount.Close()}) + $AdmissionsAccount.Controls.Add($Button_Close) + +$AdmissionsAccount.Add_Shown({$AdmissionsAccount.Activate()}) +[Void]$AdmissionsAccount.ShowDialog() + + +$NewUser = [ordered]@{FirstName=($TextBox_FName).Text; LastName=($TextBox_LName).Text; Username=($TextBox_UName).Text; Title=($TextBox_Job).Text; Employee=($TextBox_EmID).Text} + + +New-LHADUser -Details $NewUser + + +Enable-LHMailbox -Details $NewUser diff --git a/Exercise Files/03_04/03_04.ps1 b/Exercise Files/03_04/03_04.ps1 new file mode 100755 index 0000000..878c69b --- /dev/null +++ b/Exercise Files/03_04/03_04.ps1 @@ -0,0 +1,17 @@ +# Reason for analyzing +# Scripts are growing +# Human error +# Scripts are to be shared +# Quality standards are recognized as important + +Install-Module -Name PSScriptAnalyzer + +Get-Command -Module PSScriptAnalyzer + +Get-ScriptAnalyzerRule +# PSAvoidUsingCmdletAliases +# PSAvoidGlobalFunctions -- read details +# PSAvoidUsingComputerNameHardcoded -- error +# PSAvoidUsingInvokeExpression -- security hole (code insertion) + +Invoke-ScriptAnalyzer -Path ".\03_04-02.ps1" \ No newline at end of file diff --git a/Exercise Files/03_04/03_04_Analyze.ps1 b/Exercise Files/03_04/03_04_Analyze.ps1 new file mode 100755 index 0000000..abbb5d5 --- /dev/null +++ b/Exercise Files/03_04/03_04_Analyze.ps1 @@ -0,0 +1,7 @@ +$RunMe = Read-Host -Prompt 'What would you like to run today?' +Invoke-Expression -Command $RunMe + +Get-MyUsers -OU Management + +Get-Process -ComputerName dc01 | Out-File C:\ScriptOutput\Processes.txt + diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29