-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleanup-Script.ps1
More file actions
56 lines (47 loc) · 2.11 KB
/
Copy pathCleanup-Script.ps1
File metadata and controls
56 lines (47 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
$Global:Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Cleanup-Script.log"
Start-Transcript -Path (Join-Path "$env:WINDIR\Temp\" $Global:Transcript) -ErrorAction Ignore
Write-Host "Execute OSD Cloud Cleanup Script" -ForegroundColor Green
If(Test-Path $env:windir\Provisioning\Autopilot\AutoPilotConfigurationFile.json){
$CorrectComputerName = (Get-Content $env:windir\Provisioning\Autopilot\AutoPilotConfigurationFile.json -raw | ConvertFrom-Json).CloudAssignedDeviceName
}
Else{
$CorrectComputerName = $env:Computername
}
If($env:computername -ne $CorrectComputerName){
Write-Host "Renaming Computer:$env:computername to $CorrectComputerName"
Rename-Computer -Computername $env:computername -NewName $CorrectComputerName -Force
}
# Copying OSDCloud Logs
If (Test-Path -Path 'C:\OSDCloud\Logs') {
Move-Item 'C:\OSDCloud\Logs\*.*' -Destination 'C:\ProgramData\Microsoft\IntuneManagementExtension\Logs\OSD' -Force
}
# Cleanup directories
If (Test-Path -Path 'C:\OSDCloud') { Remove-Item -Path 'C:\OSDCloud' -Recurse -Force }
If (Test-Path -Path 'C:\Drivers') { Remove-Item 'C:\Drivers' -Recurse -Force }
If (Test-Path -Path 'C:\Temp') { Remove-Item 'C:\Temp' -Recurse -Force }
$Inf = @"
[Unicode]
Unicode=yes
[Version]
signature="`$CHICAGO`$"
Revision=1
[System Access]
MinimumPasswordAge = 0
MaximumPasswordAge = 720
MinimumPasswordLength = 12
PasswordComplexity = 1
PasswordHistorySize = 24
LockoutBadCount = 10
ResetLockoutCount = 5
LockoutDuration = 5
RequireLogonToChangePassword = 0
ForceLogoffWhenHourExpire = 0
"@
$Null = New-Item -Path "$Env:SystemRoot\security\database" -Name SecPolicy.inf -ItemType File -Value $Inf -Force
$Process = Start-Process -FilePath Secedit.exe -ArgumentList "/configure /db secedit.sdb /cfg $env:SystemRoot\Security\Database\SecPolicy.inf /overwrite /quiet" -NoNewWindow -PassThru -Wait
If($env:Computername -match 'Zoom|Sign'){
$RegKeyPath = "HKLM:\SOFTWARE\Policies\Microsoft\PassportForWork"
If(!(Test-Path $RegKeyPath)){New-Item $RegKeyPath | Out-Null}
New-ItemProperty -Path $RegKeyPath -Name "Enabled" -Value "0" -PropertyType DWORD -Force | Out-Null
}
Stop-Transcript