Windows10Setup.ps1
<#PSScriptInfo .VERSION 2.6.2 .GUID 78fe3fa8-add6-47e8-8c0c-06baf75ea954 .AUTHOR Mosaicmk Software LLC .COMPANYNAME Mosaicmk Software LLC .COPYRIGHT (c) 2020 MosaicMK Software LLC. All rights reserved. .TAGS Windows .LICENSEURI https://opensource.org/licenses/MS-PL .PROJECTURI https://www.mosaicmk.com .ICONURI https://3.bp.blogspot.com/-5AH8bMtdvcU/XBpsEqKMoFI/AAAAAAAABIw/cRbUnQwTwdIpZapoCD4ifYatBmy717zSgCLcBGAs/s1600/logo-transparent_NoWords.png.ico .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .SYNOPSIS Configures popular settings on a windows 10 workstation for first time use .DESCRIPTION This script can be used to remove built in windows 10 apps,Export a Custome Start Menu config file,Import a default start menu config file, Disable OneDrive, Disbale Cortana, Disable Hibernate, Join a workstation to a domain, Rename the workstation, Set the page file size, Disable Windows Tips, Disable the Consumer experience and Disable the Xbox Services. .PARAMETER RemoveApps Use this switch enable app removal .PARAMETER AppsToRemove Specifyes the list of apps to be removed, if not used then will use a list of apps built into the script .PARAMETER StartMenuLayout Specifyes the xml file for the start menu layout, Only new users on the device will get the layout Accounts that already exist will not see a change. This is due to the fact that the layout is applied to the default user profile. .PARAMETER ExportStartMenuLayout Exports the curent start menu layout to be used on other workstations .PARAMETER DisableAds Disables all ads and sujested apps from the start menu, explorer, and lock screen .PARAMETER DisableOneDrive Disables OneDrive on the workstation .PARAMETER DisableCortana Disables Cortana on the workstation .PARAMETER DisableHibernate Disables the hibernate power setting .PARAMETER SetPowerConfig Imports and sets a Power Config from a file https://docs.microsoft.com/en-us/windows-hardware/design/device-experiences/powercfg-command-line-options .PARAMETER DisableWindowsStore Disables access to the Windows Store, The app is still listed .PARAMETER DisableConsumerExperience Disables The installation of extra apps and the pinning of links to Windows Store pages of third-party applications by using this featurs like the phone app will no longer work .PARAMETER JoinDomain Joins the computer to a domain .PARAMETER Account Account used to join to a domain, if not specified you will be asked for the account .PARAMETER Domain Domain to join when the JoinDomain Parameter is used, if not specified you will be asked for the domain .PARAMETER RenameComputer Renames the workstation to what is specified for the parameter .PARAMETER SetPageFile Sets the page file size to the recomended size based on the ammount of memmory installed on the device .PARAMETER PageFileDrive Moves the page file to a new drive, if not specified will default to the C drive When specifying a drive letter just use the letter for example -PageFileDrive D .PARAMETER LogFile Specifies the location of the logfile byt default it is set to C:\Win10Setup.log the log file is in a foramt for cmtrace https://docs.microsoft.com/en-us/sccm/core/support/cmtrace .PARAMETER DisableConnectToInternetUpdates Unless specified with GPO or this reg key Windows 10 will look to other update locations to pull critial updates that have not bet installed on the device https://social.technet.microsoft.com/Forums/en-US/46f992d3-e4eb-466f-8993-b791193dae2d/forcing-windows-10-clients-to-pull-updates-from-wsus-only?forum=win10itprosetup .PARAMETER Reboot Reboots the computer after all other taskes have been performed .PARAMETER SetTimeZone Sets the Time Zone of the computer .PARAMETER InstallDotNet35 Installs .Net 3.5 from source files Source files can be located on the OS install media under D:\Sources\sxs directory .EXAMPLE .\Win10Setup.ps1 -RemoveApps -AppsToRemove AppsList.txt Removes all apps in the AppsList.txt file .EXAMPLE .\Win10Setup.ps1 -StartMenuLayout C:\example\StartMenuLayout.xml Imports the xml file to use as the default start menu layout for all new users To build your xml run Export-StartLayout -Path "C:\example\StartMenuLayout.xml" .EXAMPLE .\Win10Setup.ps1 -StartMenuLayout C:\example\StartMenuLayout.xml -RemoveApps -AppsToRemove C:\example\AppsToRemove.txt -DisableOneDrive -DisableCortana Imports the start menu config, removes apps listed in the txt file. disbales OneDrive and cortana. .EXAMPLE .\Win10Setup.ps1 -StartMenuLayout C:\example\StartMenuLayout.xml -RemoveApps -InstallDotNet35 D:\sources\sxs -SetPowerConfig C:\example\PowerPlan.pow Imports the start menu config, removes apps listed in the default list, Installs .Net 3.5 from the source files and sets the power config to the one stored in the config file .NOTES Contact: Contact@mosaicmk.com Facebook: MosaicMK Software LLC Version 2.6.2 .LINK http://www.mosacimk.com #> Param( [Switch]$RemoveApps, [string]$AppsToRemove, [string]$StartMenuLayout, [Switch]$SetPageFile, [String]$PageFileDrive, [Switch]$EnableRDP, [Switch]$DisableOneDrive, [Switch]$DisableCortana, [Switch]$DisableWindowsTips, [Switch]$DisableConsumerExperience, [Switch]$DisableHibernate, [String]$SetPowerConfig, [Switch]$DisableXboxServices, [Switch]$DisableAds, [Switch]$DisableWindowsStore, [Switch]$DisableConnectToInternetUpdates, [switch]$DisableUAC, [string]$SetTimeZone, [Switch]$JoinDomain, [string]$Account, [string]$Domain, [string]$RenameComputer, [String]$ExportStartMenuLayout, [string]$InstallDotNet35, [Switch]$Reboot, [string]$LogFile = "C:\Win10Setup.log" ) $ScriptName = $MyInvocation.MyCommand.Name $OldProgressPreference = $ProgressPreference $ProgressPreference = 'SilentlyContinue' function Invoke-Proccess { param ( [Parameter(Mandatory=$true)] [string]$Proccess, [string]$Arguments, [switch]$GetOutput ) $Guid = (New-Guid).Guid $ErrorFile = "$env:TEMP\" + $GUID + '.error' $OutFile = "$env:TEMP\" + $GUID + '.out' Start-Process -filepath $Proccess -ArgumentList "$Arguments" -NoNewWindow -RedirectStandardError $ErrorFile -RedirectStandardOutput $OutFile -Wait $ErrorText = Get-Content $ErrorFile -Raw $OutText = Get-Content $OutFile -Raw Remove-Item $ErrorFile -Force | Out-Null Remove-Item $OutFile -Force | Out-null IF ($ErrorText){Throw $ErrorText} IF ($GetOutput){ $OutPut = New-Object -TypeName psobject $OutPut | Add-Member -MemberType NoteProperty -Name Output -Value $OutText $OutPut } } function Read-Error{ PARAM( [string]$ErrorText ) Add-LogEntry -LogMessage $ErrorText -Messagetype 3 Exit-Script exit 1 } function New-LogFile{ $LogFilePaths = "$LogFile" Foreach ($LogFilePath in $LogFilePaths){ $script:NewLogError = $null $script:ConfigMgrLogFile = $LogFilePath Add-LogEntry "********************************************************************************************************************" "1" Add-LogEntry "Log file successfully intialized for $ScriptName." 1 If (-Not($script:NewLogError)) { break } } If ($script:NewLogError){ $script:Returncode = 1 Exit $script:Returncode } } function Add-LogEntry{ PARAM( $LogMessage, $Messagetype = 1 ) # Date and time is set to the CMTrace standard # The Number after the log message in each function corisponts to the message type # 1 is info # 2 is a warning # 3 is a error If ($Messagetype -eq 1){Write-Host "$LogMessage"} If ($Messagetype -eq 2){Write-Warning "$LogMessage"} If ($Messagetype -eq 3){Write-Error "$LogMessage"} Add-Content $script:ConfigMgrLogFile "<![LOG[$LogMessage]LOG]!><time=`"$((Get-Date -format HH:mm:ss)+".000+300")`" date=`"$(Get-Date -format MM-dd-yyyy)`" component=`"$ScriptName`" context=`"`" type=`"$Messagetype`" thread=`"`" file=`"powershell.exe`">" -Errorvariable script:NewLogError } function Exit-Script{ $ProgressPreference = $OldProgressPreference Add-LogEntry "Closing the log file for $ScriptName." Add-LogEntry "********************************************************************************************************************" } Function Export-StartMenuLayout{ Export-StartLayout -Path "$ExportStartMenuLayout" Write-Host "Config Saved To: $ExportStartMenuLayout" exit 0 } Function Import-StartMenuLayout{ Add-LogEntry -LogMessage "Importing startmenu layout: $StartMenuLayout" try { Import-StartLayout -LayoutPath $StartMenuLayout -MountPath C:\ -ErrorAction Stop Add-LogEntry "SUCCESS: Start menu layout was succefully imported" <# This is for future work to try and apply the statrt menu for profiles that are already created New-Item -Path HKCU:\SOFTWARE\Policies\Microsoft\Windows -Name Explorer -ErrorAction SilentlyContinue | Out-Null New-ItemProperty HKCU:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name LockedStartLayout -PropertyType string -Value 1 -Force | Out-Null New-ItemProperty HKCU:\SOFTWARE\Policies\Microsoft\Windows\Explorer -Name StartLayoutFile -PropertyType ExpandString -Value "$StartMenuLayout" -Force | Out-Null Stop-Process -Name explorer -Force Start-Sleep -s 10 Remove-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\Explorer" -Name "LockedStartLayout" -Force Remove-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\Explorer" -Name "StartLayoutFile" -Force #> }catch {Add-LogEntry -LogMessage "ERROR: Unable to import start menu layout: $_" -Messagetype 3} } Function Disable-OneDrive{ Add-LogEntry -LogMessage "Disabling OneDrive" $RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive" $Name = "DisableFileSyncNGSC" $Value = "1" $Type = "DWORD" Set-Location HKLM: if (!(test-Path .\SOFTWARE\Policies\Microsoft\Windows\OneDrive)) {New-Item .\SOFTWARE\Policies\Microsoft\Windows\OneDrive} try { New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force -ErrorAction Stop | Out-Null Add-LogEntry -LogMessage "SUCCESS:OneDrive scusessfuly disabled" } catch {Add-LogEntry "ERROR: Unale to disble OneDrive: $_" -Messagetype 3} Set-Location $PSScriptRoot } Function Disable-XboxServices{ Add-LogEntry -LogMessage "Disabling Xbox Services" try { Get-Service XblAuthManager -ErrorAction Stop | stop-service -passthru -ErrorAction Stop | set-service -startuptype disabled -ErrorAction Stop $AppsList = Get-AppxProvisionedPackage -online | where-object {$_.displayname -like "*xbox*"} if ($AppsList){ foreach($Item in $AppsList){ Remove-AppxProvisionedPackage -Online -PackageName $item.PackageName -ErrorAction Stop | Out-Null Get-AppxPackage -AllUsers -Name $Item.DisplayName | Remove-AppxPackage -ErrorAction Stop | Out-Null } } Add-LogEntry -LogMessage "SUCCESS: Disabled Xbox Services" }catch {Add-LogEntry -LogMessage "ERROR: Unable to Disable Xbox Services: $_" -Messagetype 3} } Function Disable-UAC{ Add-LogEntry -LogMessage "Disabling UAC" Set-Location HKLM: if (!(test-Path .\Software\Microsoft\Windows\CurrentVersion\policies\system)) {New-Item .\Software\Microsoft\Windows\CurrentVersion\policies\system | Out-Null} try { New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force | Out-Null Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "ConsentPromptBehaviorAdmin" -Value 00000000 -Force | Out-Null Add-LogEntry -LogMessage "SUCCESS: Disabled UAC" } catch {Add-LogEntry -LogMessage "ERROR: Unable to disable UAC: $_" -Messagetype 3} Set-Location $PSScriptRoot } Function Disable-Cortana{ Add-LogEntry -LogMessage "Disabling Cortana" $RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" $Name = "AllowCortana" $Value = "0" $Type = "DWORD" Set-Location HKLM: if (!(test-Path .\SOFTWARE\Policies\Microsoft\Windows\"Windows Search")) {New-Item .\SOFTWARE\Policies\Microsoft\Windows\"Windows Search" | Out-Null} try { New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force -ErrorAction Stop | Out-Null Add-LogEntry -LogMessage "SUCCESS: disabled Cortana" } catch {Add-LogEntry -LogMessage "ERROR: Unable to disable Cortana: $_" -Messagetype 3} Set-Location $PSScriptRoot } Function Disable-WindowsTips{ Add-LogEntry -LogMessage 'Disabling Windows Tip' $RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" $Name = "DisableSoftLanding" $Value = "1" $Type = "DWORD" Set-Location HKLM: if (!(test-Path .\SOFTWARE\Policies\Microsoft\Windows\CloudContent)) {New-Item .\SOFTWARE\Policies\Microsoft\Windows\CloudContent | Out-Null} try { New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force -ErrorAction Stop Add-LogEntry -LogMessage "SUCCESS: disabled Windows Tips" } catch {Add-LogEntry -LogMessage "ERROR: Unsable to disable Windows Tips: $_" -Messagetype 3} Set-Location $PSScriptRoot } Function Disable-ConsumerExperience{ Add-LogEntry -LogMessage 'Disabling Consumer Experience' $RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" $Name = "DisableWindowsConsumerFeatures" $Value = "1" $Type = "DWORD" Set-Location HKLM: if (!(test-Path .\SOFTWARE\Policies\Microsoft\Windows\CloudContent)) {New-Item .\SOFTWARE\Policies\Microsoft\Windows\CloudContent | Out-Null} try { New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force -ErrorAction Stop | Out-Null Add-LogEntry -LogMessage "SUCCESS: disabled Consumer Experience" }catch {Add-LogEntry -LogMessage "ERROR: Unable to disabled Consumer Experience: $_" -Messagetype 3} Set-Location $PSScriptRoot } Function Disable-Hibernate{ Add-LogEntry -LogMessage "Disabling Hibernate" powercfg.exe /hibernate off If (!(test-Path -path $Env:SystemDrive\Hiberfil.sys)){ Add-LogEntry -LogMessage "SUCCESS: Hibernate Disabled" } IF (Test-Path -Path $Env:SystemDrive\Hiberfil.sys){Add-LogEntry -LogMessage "ERROR: Hibernate was not disabled" -Messagetype 3} } Function Disable-Ads{ $reglocation = "HKCU" #Start menu ads Add-LogEntry 'Disabling Start Menu Ads for Current User' Reg Add "$reglocation\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" /T REG_DWORD /V "SystemPaneSuggestionsEnabled" /D 0 /F #Lock Screen suggestions Add-LogEntry 'Disabling Lock Screen Suggentions for Current User' Reg Add "$reglocation\SOFTWARE\Microsoft\CurrentVersion\ContentDeliveryManager" /T REG_DWORD /V "SoftLandingEnabled" /D 0 /F Add-LogEntry "Disabling explorer ads for current user" Reg Add "$reglocation\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /T REG_DWORD /V "ShowSyncProviderNotifications" /D 0 /F $reglocation = "HKLM\AllProfile" reg load "$reglocation" c:\users\default\ntuser.dat IF ($LASTEXITCODE -ne 0) {Add-LogEntry "Could not mount default user profile reg hive" -Messagetype 3} IF ($LASTEXITCODE -eq 0){ Add-LogEntry 'Disabling Start Menu Ads for default user' Reg Add "$reglocation\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" /T REG_DWORD /V "SystemPaneSuggestionsEnabled" /D 0 /F IF ($LASTEXITCODE -ne 0) {Add-LogEntry "ERROR: Could not disable Start Menu Ads for default user" -Messagetype 3} Else {Add-LogEntry -LogMessage "SUCCESS: Disabled Start Menu Ads for default user"} Add-LogEntry 'Disabling Lock Screen Suggentions for Current User' Reg Add "$reglocation\SOFTWARE\Microsoft\CurrentVersion\ContentDeliveryManager" /T REG_DWORD /V "SoftLandingEnabled" /D 0 /F IF ($LASTEXITCODE -ne 0) {Add-LogEntry "ERROR: Could not disable Lock Screen Suggentions for Current User" -Messagetype 3}Else {Add-LogEntry -LogMessage "SUCCESS: Disabled Lock Screen Suggentions for Current User"} Add-LogEntry "Disabling explorer ads for default user" Reg Add "$reglocation\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /T REG_DWORD /V "ShowSyncProviderNotifications" /D 0 /F IF ($LASTEXITCODE -ne 0) {Add-LogEntry "ERROR: Could not disable explorer ads for default user" -Messagetype 3}Else {Add-LogEntry -LogMessage "SUCCESS: Disabled explorer ads for default user"} #unload default user hive [gc]::collect() reg unload "$reglocation" IF ($LASTEXITCODE -ne 0) {Add-LogEntry "ERROR: Could not dismount default user reg hive" -Messagetype 3} } } Function Disable-WindowsStore{ Add-LogEntry -LogMessage 'Disabling Windows Store' $RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent" $Name = "DisableSoftLanding" $Value = "1" $Type = "DWORD" Set-Location HKLM: if (!(test-Path .\SOFTWARE\Policies\Microsoft\Windows\CloudContent)) {New-Item .\SOFTWARE\Policies\Microsoft\Windows\CloudContent | Out-Null} try { New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force -ErrorAction Stop Add-LogEntry -LogMessage "SUCCESS: Windows Store was disabled" } catch {Add-LogEntry -LogMessage "ERROR: Windows Store was not disabled: $_" -Messagetype 3} Set-Location $PSScriptRoot } Function Remove-Apps{ Add-LogEntry -LogMessage "Starting App Removeal" -Messagetype 1 If ($AppsToRemove){ If (!(Test-Path $AppsToRemove)){Read-Error -ErrorText "ERROR: Could not find $AppsToRemove"} $AppsList = Get-Content $AppsToRemove } If (!($AppsToRemove)){$AppsList = Get-AppxProvisionedPackage -online | where-object {$_.displayname -notlike "*Store*" -and $_.displayname -notlike "*Calculator*" -and $_.displayname -notlike "*Windows.Photos*" -and $_.displayname -notlike "*SoundRecorder*" -and $_.displayname -notlike "*MSPaint*" -and $_.displayname -notlike "*ZuneVideo*" -and $_.displayname -notlike "*BingWeather*" -and $_.displayname -notlike "*sticky*" }} #Removes some windows apps Foreach ($item in $AppsList){ $Name = $item.Displayname Add-LogEntry -LogMessage "Attemptng to remove $Name Provisioned Package" try { Remove-AppxProvisionedPackage -Online -PackageName $item.PackageName -ErrorAction Stop | Out-Null Add-LogEntry -LogMessage "SUCCESS: $name Provisioned Package was succefully removed" } catch { Add-LogEntry -LogMessage "Could not remove $name Provisioned Package, will retry: $_" -Messagetype 2 try { Remove-AppxProvisionedPackage -Online -PackageName $item.PackageName -ErrorAction Stop | Out-Null Add-LogEntry "SUCCESS: Retry for removal of $name Provisioned Pakcage was succefull" } catch {Add-LogEntry -LogMessage "ERROR: Could not remove $Name Provisioned Package: $_" -Messagetype 3} } Add-LogEntry -LogMessage "Attemptng to remove $Name Package" try { Get-AppxPackage -AllUsers -Name $Item.DisplayName | Remove-AppxPackage -ErrorAction Stop | Out-Null Add-LogEntry -LogMessage "SUCCESS: $Name package was succefully removed" } catch { Add-LogEntry -LogMessage "$Name package was not removed, will retry: $_" -Messagetype 2 try { Get-AppxPackage -AllUsers -Name $Item.DisplayName | Remove-AppxPackage -ErrorAction Stop | Out-Null Add-LogEntry -LogMessage "SUCCESS: $Name package was succefully removed" } catch {Add-LogEntry -LogMessage "ERROR: $Name package was not removed: $_" -Messagetype 3} } } } Function Set-PageFile{ #Gets total memory $Getmemorymeasure = Get-WMIObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum #Converts the memory into GB $TotalMemSize = $($Getmemorymeasure.sum/1024/1024/1024) if (!($PageFileDrive)){$Drive = "C:"}else{IF ($PageFileDrive -like "*:"){$Drive = $PageFileDrive}else{$Drive = $PageFileDrive + ":"}} #recomended Page file size is double the memory installed Add-LogEntry -LogMessage "Setting Page file size on: $Drive" Add-LogEntry -LogMessage "Total Memory Installed (gb): $TotalMemSize" try { #2gb If (($TotalMemSize -gt "1") -and ($TotalMemSize -le "2.1")){Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 4096 4096" -ErrorAction Stop} #4gb If (($TotalMemSize -gt "2") -and ($TotalMemSize -le "4.1")){Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 8194 8194" -ErrorAction Stop} #6gb If (($TotalMemSize -gt "4") -and ($TotalMemSize -le "6.1")){Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 12288 12288" -ErrorAction Stop} #8gb If (($TotalMemSize -gt "6") -and ($TotalMemSize -le "8.1")){Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 16384 16384" -ErrorAction Stop} #12 If (($TotalMemSize -gt "8") -and ($TotalMemSize -le "12.1")){Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 24576 24576" -ErrorAction Stop} #16 If (($TotalMemSize -gt "12") -and ($TotalMemSize -le "16.1")){Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 32768 32768" -ErrorAction Stop} #24 If (($TotalMemSize -gt "16") -and ($TotalMemSize -le "24.1")){Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 49152 49152" -ErrorAction Stop} #32 If (($TotalMemSize -gt "24") -and ($TotalMemSize -le "32.1")){Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 65536 65536" -ErrorAction Stop} #64 If (($TotalMemSize -gt "32") -and ($TotalMemSize -le "64.1")){Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 131072 131072" -ErrorAction Stop} Add-LogEntry -LogMessage "SUCCESS: Set page file size" }catch {Add-LogEntry -LogMessage "ERROR: Could not set page file: $_" -Messagetype 3} } function Enable-RDP{ Add-LogEntry -LogMessage "Enabling RDP" try { Get-NetFirewallProfile | Set-NetFirewallProfile -Enabled "False" -ErrorAction Stop If (Get-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections"){Set-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value "0"}Else{New-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value "0"} Add-LogEntry -LogMessage "SUCCESS: Enabled RDP" }catch {Add-LogEntry "ERROR: Could not enable RDP: $_" -Messagetype 3} } function Join-Domain{ IF (!($Domain)) {$domain = Read-Host "Domain"} IF (!($Account)) {$account = Read-Host "Account"} $password = Read-Host "Password for $Account" -AsSecureString Write-host "Joining $Domain as $Account" $username = "$domain\$account" $credential = New-Object System.Management.Automation.PSCredential($username,$password) Add-Computer -DomainName $domain -Credential $credential $password = $null $credential = $null } Function Set-Time{ Add-LogEntry -LogMessage "Setting Time Zone" try { Set-TimeZone -Name "$SetTimeZone" -ErrorAction Stop Add-LogEntry -LogMessage "SUCCESS: set Time Zone" } catch {Add-LogEntry -LogMessage "ERROR: Could not set Time Zone" -Messagetype 3} } Function Set-PowerConfig{ Add-LogEntry -LogMessage "Setting power config" $out = Invoke-Proccess -Proccess powercfg.exe -Arguments "/IMPORT `"$SetPowerConfig`"" -GetOutput $guid = $out.Output.substring(42) Invoke-Proccess -Proccess powercfg.exe -Arguments "/s $guid" } Function Disable-ConnectToInternetUpdates{ Add-LogEntry -LogMessage 'Disabling Connect To Internet Updates' $RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" $Name = "DoNotConnectToWindowsUpdateInternetLocations" $Value = "1" $Type = "DWORD" Set-Location HKLM: if (!(test-Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate")) {New-Item "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" | Out-Null} try { New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force -ErrorAction Stop Add-LogEntry -LogMessage 'SUCCESS: Connect to Internet for Updates was disabled' } catch {Add-LogEntry -LogMessage "ERROR: Connect to Internet for Updates was not disabled: $_" -Messagetype 3} Set-Location $PSScriptRoot } function Install-Dotnet { Add-LogEntry -LogMessage "Installing .Net 3.5" try { Get-WindowsCapability -Name "NetFx3*" -Online | Add-WindowsCapability -Online -Source $InstallDotNet35 -InformationAction SilentlyContinue -ErrorAction Stop | Out-Null Add-LogEntry -LogMessage "SUCCESS: .Net 3.5 was installed" } catch {Add-LogEntry -LogMessage "Unable to install .Net 3.5 : $_" -Messagetype 3} } #Checks to see what switches are being used If (($StartMenuLayout) -and ($ExportStartMenuLayout)){Read-Error -ErrorText "You can not use ExportStartMenuLayout parameter and StartMenuLayout parameter at the sametime"} #Exports the current start menu config If ($ExportStartMenuLayout){Export-StartMenuLayout} New-LogFile #If a config file is specifed will import it IF ($StartMenuLayout) {Import-StartMenuLayout} #Enable RDP IF ($EnableRDP) {Enable-RDP} #Sets the Tiemzone IF ($SetTimeZone) {Set-Time} #Disabled UAC IF ($DisableUAC){Disable-UAC} #Disbales Xbox Services and stops them If ($DisableXboxServices) {Disable-XboxServices} #Add regkeys to disable OneDrive If ($DisableOneDrive) {Disable-OneDrive} #adds regkey needed to disable Cortana If ($DisableCortana) {Disable-Cortana} #Disables the windows store, The app is still listed If ($DisableWindowsStore) {Disable-WindowsStore} #Disables add on the start menu and lock screen If ($DisableAds) {Disable-Ads} #Disables Hibernate If ($DisableHibernate) {Disable-Hibernate} #Disables Windows Tips If ($DisableWindowsTips) {Disable-WindowsTips} #Disables Consumer Experience If ($DisableConsumerExperience) {Disable-ConsumerExperience} #Disable Connect to Windows Update Internet Location IF ($DisableConnectToInternetUpdates) {Disable-ConnectToInternetUpdates} #If a list file is specifyed will run the uninstall process IF ($RemoveApps) {Remove-Apps} if ($InstallDotNet35){Install-dotnet} #renames the computer If ($RenameComputer) {Rename-Computer -NewName $RenameComputer} #Sets the page file If ($SetPageFile) {Set-PageFile} #Sets power config IF ($SetPowerConfig) {Set-PowerConfig} #Reboots the computer If ($Reboot){Restart-Computer -ComputerName $env:COMPUTERNAME ; Exit-Script}else{ Write-Host "You will need to reboot the computer before you see the change take affect" Exit-Script } |