Windows 10 Setup Script - V 2.0.0.0

Over the past few weeks I have been revisiting how I setup new workstations both with SCCM and manually.  There are a few script I put together to configure things like the page file and disable Cortana. These scripts are useful but hard to always keep up to date and if I want to use them in a SCCM TS then I need make a step and package for each script. So I have consolidated these script into the Win10Setup script. The script will still remove built in apps and import a custom start menu config file, Below are the changes I have made to the script.
  • A default list of apps to remove if a txt file of apps is not specified
  • Switch to export your start menu layout to use for deployment
  • Parameters to join a computer to a domain (not usable with SCCM or other deployment automation applications)
  • Switch to disable the Consumer Experience
  • Switch to stop and disable Xbox services
  • Switch to move and set the page file 
  • Switch to disable the hibernate power option
  • Switch to disable Windows Tips
  • Switch to reboot the computer (Not recommenced with SCCM or MDT)
In some of my posts I have talked about how you can use this script to configure windows 10. If you have used the script you will want to change the command line for the task to the -Command instead of -file. By using the -Command parameter you can specify what parameters from the script you want to use rather then specifying the parameters in the script its self. Below is a idea of what your task should look like.








<#
.SYNOPSIS
Configures popular settings on a 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

.PARAMETER DisableOneDrive
Disables OneDrive on the workstation

.PARAMETER DisableCortana
Disables Cortana on the workstation

.PARAMETER ExportStartMenuLayout
Exports the curent start menu layout to be used on other workstation

.PARAMETER DisableHibernate
Disables the hibernate power setting

.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 ammount 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

.PARAMETER Reboot 
Reboots the computer after all other taskes have been performed

.EXAMPLE
.\Win10Setup.ps1 -RemoveApps -AppsToRemove AppsList.txt
Removes all apps in the AppsList.txt file

.EXAMPLE
.\Win10Setup.ps1 -StartMenuLayout 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 StartMenuLayout.xml -RemoveApps -AppsToRemove AppsToRemove.txt -DisableOneDrive -DisableCortana
Imports the start menu config removes apps listed in the txt file disbales one drive and cortana.

.NOTES
Created By: Kris Gross
Contact: Krisgross@sccmtst.com
Twitter: @kmgamd
Version 2.0.0.0

.LINK
You can get updates to this script and others from here
http://www.sccmtst.com/
#>

Param(
    $AppsToRemove,
    [Switch]$RemoveApps,
    $StartMenuLayout,
    [Switch]$DisableOneDrive,
    [Switch]$DisableCortana,
    [Switch]$DisableWindowsTips,
    [Switch]$DisbaleConsumerExperience,
    [Switch]$ExportStartMenuLayout,
    [Switch]$JoinDomain,
    $Account,
    $Domain,
    $RenameComputer,
    [Switch]$DisableHibernate,
    [Switch]$DisableXboxServices,
    [Switch]$SetPageFile,
    $PageFileDrive,
    [Switch]$Reboot
    )

#Checks to see what switches are being used 
If (($StartMenuLayout) -and ($ExportStartMenuLayout))
{
        Write-error "You can not use ExportStartMenuLayout parameter and StartMenuLayout parameter at the sametime"  
}
else 
{
    #Exports the current start menu config 
    If ($ExportStartMenuLayout)
    {
        $ExportFile = Read-Host "Export Config Name (Must be a XLM file)"
        Export-StartLayout -Path "$PSScriptRoot\$ExportFile"
        Write-Host "Config Saved To: $PSScriptRoot\$ExportFile"
    }

    #Disbales Xbox Services and stops them
    If ($DisableXboxServices)
    {
        Write-Host "Disabling Xbox Services"
        Get-Service XblAuthManager,XblGameSave,XboxNetApiSvc,WMPNetworkSvc | stop-service -passthru | set-service -startuptype disabled
    }

    #If a list file is specifyed will run the uninstall process
    IF ($RemoveApps)
    {
        If ($AppsToRemove) 
        {
            $AppsList = Get-Content $AppsToRemove
        }
        If (!($AppsToRemove))
        {
            $AppsList = @("3dbuilder","windowscommunicationsapps","getstarted","skypeapp","FeedBack","solitairecollection","onenote","Office.sway","Twitter","xbox","bingnews","News","people","messaging","officehub","Connect","ContactSupport")
        }
        #Removes some windows apps
        Foreach ($App in ($AppsList))
        {
            $item = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -Like "*$App*"} 
            Write-Host "Removing $App"
            Remove-AppxProvisionedPackage -Online -PackageName $item.PackageName -erroraction silentlycontinue
            Get-AppxPackage -AllUsers | Where-Object Name -Like "*$App*" | Remove-AppxPackage -erroraction silentlycontinue
        }
    }
    
    #Disables Windows Tips
    If ($DisableWindowsTips)
    { 
        Write-Host '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}
        New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null
        Set-Location $PSScriptRoot
        Write-Host "You will need to reboot the computer before you see the change take affect"
    }

    #Disables Consumer Experience
    If ($DisbaleConsumerExperience)
    {
        Write-Host '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}
        New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null
        Set-Location $PSScriptRoot
        Write-Host "You will need to reboot the computer before you see the change take affect"
    }

    #If a config file is specifed will import it 
    IF ($StartMenuLayout)
    {
        #Configures the start menu layout
        Write-Host importing $StartMenuLayout
        #Copyies a IE Shortcut to the all users start menu so all users will have it on the start menu
        #Copy-Item -Path "Internet Explorer.lnk" -Destination "C:\ProgramData\Microsoft\Windows\Start Menu\Programs"
        Import-StartLayout -LayoutPath $StartMenuLayout -MountPath C:\
    }

    #Add regkeys to disable OneDrive
    If ($DisableOneDrive)
    {
        Write-Host '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}
        New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null
        Set-Location $PSScriptRoot
        Write-Host "You will need to reboot the computer before you see the change take affect"
    }

    #adds regkey needed to disable Cortana
    If ($DisableCortana)
    {
        Write-Host "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"}
        New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null
        Set-Location $PSScriptRoot
        Write-Host "You will need to reboot the computer before you see the change take affect"
    }

    #renames the computer
    If ($RenameComputer)
    {
        Rename-Computer -NewName $RenameComputer
        Write-Host "You will need to reboot the computer before you see the change take affect"
    }

    #joins the computer to a domain
    If ($JoinDomain)
    {
        IF (!$Domain){$domain = Read-Host "Domain"}
        IF (!$Account){$account = Read-Host "Account"}
        Write-host "Joining $Domain as $Account"
        $password = Read-Host "Password for $Account" -AsSecureString
        $username = "$domain\$account" 
        $credential = New-Object System.Management.Automation.PSCredential($username,$password)
        Add-Computer -DomainName $domain -Credential $credential
        Write-Host "You will need to reboot the computer before you see the change take affect"
    }

    #Disables Hibernate
    If ($DisableHibernate)
    {
        powercfg.exe /hibernate off
        If (!(test-Path -path $Env:SystemDrive\Hiberfil.sys)) {Write-Host "Hibernate Disabled"}
        IF (Test-Path -Path $Env:SystemDrive\Hiberfil.sys) {Write-Host "Hibernate was not Disabled"}
    }

    #Sets the page file
    If ($SetPageFile)
    {
        #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 -eq $null)
        {
            $Drive = "C:"
        }
        else 
        {
            $Drive = $PageFileDrive + ":"
        }
        #recomended Page file size is double the memory installed
        Write-Host "Moving Page file to: $Drive"
        write-host "Total Memory Installed (gb): $TotalMemSize"
        #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"
            Write-Host "Set page file for 2 gb of memory"
        }
        #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"
            Write-Host "Set page file for 4 gb of memory"
        }
        #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"
            Write-Host "Set page file for 6 gb of memory"
        }
        #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"
            Write-Host "Set page file for 8 gb of memory"
        }
        #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"
            Write-Host "Set page file for 12 gb of memory"
        }
        #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"
            Write-Host "Set page file for 16 gb of memory"
        }
        #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"
            Write-Host "Set page file for 24 gb of memory"
        }
        #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"
            Write-Host "Set page file for 32 gb of memory"
        }
        #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"
            Write-Host "Set page file for 32 gb of memory"
        }
        Write-Host "You will need to reboot the computer before you see the change take affect"
    }

    #Reboots the computer
    If ($Reboot)
    {
        Restart-Computer -ComputerName $env:COMPUTERNAME
    }
    # #If reboot switch and ExportStartMenuLayout parameter are not used then will ask to reboot
    # If (!($Reboot) -and (!($ExportStartMenuLayout)))
    # {
    #     $RebootCheck = Read-Host "Do you Want to reboot now? (Y,N)"
    #     if ($RebootCheck -eq "Y") {Restart-Computer -ComputerName $env:COMPUTERNAME}
    # }
}

Popular posts from this blog

SCCM Task Sequence GUI - How to set up the TS to work with a GUI

SCCM Applications vs. SCCM Packages: Understanding the Key Differences

How to Deploy a Windows 10 Servicing update as a Application