first commit

This commit is contained in:
Iwan Clement
2020-11-03 18:55:20 +01:00
commit 1808f43f53
12 changed files with 354 additions and 0 deletions

View File

@@ -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"
}
}
}

View File

@@ -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"
}
}
}

View File

@@ -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"
}
}
}

54
Exercise Files/01_04/01_04.ps1 Executable file
View File

@@ -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

34
Exercise Files/01_05/01_05.ps1 Executable file
View File

@@ -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

29
Exercise Files/01_06/01_06.ps1 Executable file
View File

@@ -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

22
Exercise Files/02_03/02_03.ps1 Executable file
View File

@@ -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

9
Exercise Files/02_04/02_04.ps1 Executable file
View File

@@ -0,0 +1,9 @@
New-PSSessionConfigurationFile -SessionType RestrictedRemoteServer -Path C:\JEA\JEAEndpoint1.pssc
Test-PSSessionConfigurationFile -Path C:\JEA\JEAEndpoint1.pssc # should yield True

62
Exercise Files/03_03/03_03.ps1 Executable file
View File

@@ -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

17
Exercise Files/03_04/03_04.ps1 Executable file
View File

@@ -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"

View File

@@ -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

0
README.md Normal file
View File