Tag Archives: Windows 10

DiskCleanup – Remove Previous Windows Versions – PowerShell Module

Over the last few weeks I have upgraded and reinstalled a number of Windows 10 machines and as part of my routine after an upgrade to a later build of Windows 10 I would clean up both the Upgrade files as well as the old version of Windows. The steps to do this involves starting the Disk Cleanup tool, with Administrative credentials, and clicking through the interface in order to clean up the files and save up some of those precious GBs of storage space. After repeating this process a few times in the past week it started to become a bit tedious.

In order to do this is use the command line options that are available with the Disk Cleanup tool, cleanmgr.exe. While it is unfortunately not possible to use this tool directly to clean up specifically the left over files of an Upgrade of Windows 10, it does allow for using the GUI to create a ‘StateFlags’ which is stored in the registry. Using this methodology in combination with Sysinternals Procmon I established where this information was written in the registry and I came up with the following three lines of PowerShell code that allowed me to create the job required to do this job:

1
2
3
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Setup Files' -PropertyType 'DWORD' -Force -Name 'StateFlags1337' -Value 0x2
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations' -PropertyType 'DWORD' -Force -Name 'StateFlags1337' -Value 0x2
cleanmgr.exe /SAGERUN:1337

This will code will first create two registry keys and after creating those registry keys, specify the Disk Cleanup application to run with job number 1337. This worked, although unfortunately it is not possible to hide the GUI completely as user interaction might still be required. In certain scenarios you will be prompted to confirm that you really do want to delete the Old Windows Installation files, that includes the warning that deleting those files will not allow you to roll back to an older version of Windows anymore. This also includes the files if you upgrades from Windows 7/8.1 to Windows 10.

As I saw more potential for this method of utilizing the Disk Cleanup tool, I decided to write a proper module that does simplifies the job creation process beyond just cleaning up Previous Windows Installation / Upgrade files. Today I have released the module that does contains the following functions:

  • Get-VolumeCachesKey
  • Get-VolumeCachesStateFlags
  • Remove-WindowsUpgradeFiles
  • Set-VolumeCachesStateFlags

To install the module on your system you can run the following code:

1
Install-Module DiskCleanup -Verbose

InstallModuleDiskCleanup

To remove  the Previous Windows Installation / Upgrade files run the following command:

1
Remove-WindowsUpgradeFiles -Verbose -Confirm:$false

RemoveUpgradeFiles

This will both create the job with number 1337 and then execute that job, and the Disk Cleanup Windows will appear on your screen. This process can take a few minutes depending on the speed of your system. The function will wait until all Disk Cleanup windows have been closed and then show a report of the amount of space saved.
DiskCleanup

Use the Get-VolumeCachesStateFlags cmdlet it is possible to view what settings have been configured:
Get-VolumeCachesStateFlags

It is also possible to setup a custom job using the Set-VolumeCachesStateFlags cmdlet, the mandatory parameter -StateFlags will accept any number of Switch parameters. These parameters are dynamically generated based on the available Keys in the registry path:

HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Setup Files

SetVolumeCachesStateFlags

The module is available at the following online repositories:

I will actively maintain this module, so feel free to leave a comment or feature request in the comments or send in a pull request on GitHub.

All the links mentioned in this article are available below:

Links in this Article
PowerShell Gallery – DiskCleanup
TechNet Script Gallery – DiskCleanup
GitHub – JaapBrasser – DiskCleanup
Sysinternals – Process Monitor

 

Uploaded CustomizeWindows10 Module to PowerShell Gallery

Today I finished another major update to the CustomizeWindows10 module I have been working on together with Jan Egil Ring. This module started as a means for me to configure/tweak Windows 10. When I was experimenting with the various Windows 10 insider builds I found myself configuring the same settings on each deployment and I was looking to simplify this process. The module contains a number of tweaks and configuration options to customize and personalize the Windows 10 experience.

CustomizeWindows10-0.0.0.4

In the past I have uploaded the majority of my scripts and functions to the TechNet Script Gallery, but recently I have started using GitHub as a version control system for my scripts. Eventually I plan to upload my entire collection of scripts to GitHub as it provides the opportunity for easier interaction with a wider community but for now this module is my first experiment with both the PowerShell Gallery as well as GitHub.

The module consists of both a PowerShell module as well as a DSC module to allow complete flexibility when applying these settings. In the following example the module will be used to ensure that hidden files are visible and that file extensions are always shown:

1
2
3
4
Import-Module -Name CustomizeWindows10
Enable-ShowFileExtension
Enable-ShowHiddenFiles
Get-ShowHiddenFiles

CustomizeWindows10-CodeExample

For more information or the direct download links of these scripts please refer to the links below. Feel free to leave a comment either here or to contribute directly on GitHub.

TechNet Script Gallery
My entries in TechNet Script Gallery
Blog.PowerShell.No – Jan Egil Ring
JaapBrasser.com – Scripts
GitHub – CustomizeWindows10
PowerShellGallery – CustomizeWindows10
TechNet Script Gallery – CustomizeWindows10

 

Video Presentation with Experts Live TV available online on Channel9 and YouTube

Last week I met up with Bert Wolters for a video presentation/interview. Bert has been recording a series of sessions on the latest and greatest functionality in Windows 10 and in this episode I discuss some of the new functionalities in PowerShell 5.0 in combination with Windows 10. The video has been recorded in Dutch, so unfortunately it will a bit hard to follow for the English speaking community.

In the video I showcase the following features:

  • Better Multiline support for the PowerShell console
  • Colored console for cmdlets, parameters and arguments
  • PowerShell cmdlets for Windows Defender
  • PowerShell debugging in the ISE using <CTRL> + B
  • DuPSUG, Dutch PowerShell User Group

Alternatively the video is also available on Microsoft’s Channel9:

For more information or the direct link of the video in this article please refer to the links below. Feel free to leave a comment either here or in the YouTube comment section.

Links in the article
Channel9 – Experts Live TV – 10 weken Windows 10 – Aflevering 9 – Powershell 5
Channel9 – Windows 10 in 10 Minuten
YouTube – Experts Live TV – 10 weken Windows 10 – Aflevering 9 – Powershell 5
DuPSUG.com, Dutch PowerShell User Group

Clear-RecycleBin New PowerShell 5.0 cmdlet, available in Windows 10

In PowerShell 5.0 a new cmdlet has been introduced that provides the ability to clear the Recycle Bin programmatically. It supports the following four parameters:

  1. DriveLetter
  2. Force
  3. WhatIf
  4. Confirm

Unfortunately there is no Get-RecycleBin cmdlet, for this purpose I have written a short function that enumerates the contents of Recycle Bin for the current user:

1
2
3
4
Function Get-RecycleBin {
    (New-Object -ComObject Shell.Application).NameSpace(0x0a).Items() |
	Select-Object Name,Size,Path
}

Get-RecycleBin

By verifying this output we can now determine if we would like to Clear the Recycle Bin or if some files that are stored there should be recovered before deleting all files. The following command will delete all files from the Recycle Bin for all drive letters:

1
Clear-RecycleBin

Clear-RecycleBin

The default mode of operation of this cmdlet is to ask for confirmation before deleting all files. This is similar behavior to right clicking the icon of Recycle Bin and clicking ‘Empty Recycle Bin’. To delete the files without confirmation the following code can be used:

1
Clear-RecycleBin -Force

Alternatively the Confirm parameter can also be explicitly set to $false:

1
Clear-RecycleBin -Confirm:$false

Unfortunately there is no online help available for this cmdlet, so for more information about this cmdlet please refer to the built-in help in PowerShell:

1
Get-Help Clear-RecycleBin -ShowWindow

For more information or the direct download links of these scripts please refer to the links below. Feel free to leave a comment either here or in the TechNet Script Library.

TechNet Script Gallery
My entries in TechNet Script Gallery
Get-RecycleBin – shows the contents of the Recycle Bin

Windows 10: Using the Get-WindowsUpdateLog cmdlet

This post is part of the Windows 10 blog series in which I will look at a number of new functionalities in Windows 10 as well as new functionality in PowerShell 5.0. In every article I will highlight a specific cmdlet or technology and provide additional information about the cmdlet

The recently introduced Get-WindowsUpdateLog cmdlet merges the Windows Update logs that are stored in ETL files together into a single plain text log file. The following command can be used to convert these log to a log file:

1
Get-WindowsUpdateLog -LogPath $env:temp\UpdateLog.log

Get-WindowsUpdateLog

Unfortunately the output from this cmdlet is send directly to the host, so it is not possible to store this information in a variable or to interact with it in a meaningful way. I hope this will be corrected before release as it makes it a bit cumbersome to interact with this cmdlet.

The cmdlet works by a three steps process:

  1. Read Information from the .etl files
  2. Convert to intermediate format, either CSV or XML
  3. Convert the intermediate to text and output to the specified logpath

To view the information stored in the intermediate file, which is in a nice structured format the following code can be used:

1
Import-Csv -Path C:\Users\JAAPBR~1\...\wuetl.CSV.tmp.00000

The converted log is available in the specified path, to open the log file in the default text editor, usually notepad, the Invoke-Item can be used:

1
Invoke-Item -Path $env:temp\UpdateLog.log

NotepadWindowsUpdateLog

Get-WindowsUpdateLog
Get-WindowsUpdateLog

Windows 10 Build 10159 Released – Start of Windows 10 Blog Series

W10B10159Microsoft announced the release of the latest build of Windows 10, Build 10159: Whoa! Another PC build!, it is available for download if you set the Windows Update settings to Fast. By setting it on this mode, Windows Update will automatically download the latest build when it becomes available.

To get the most recent preview builds installed on your Windows 10 Technical Preview build navigate to:

  • Advanced Update Settings
  • Choose how preview builds are installed
  • Set Pull-down menu to ‘Fast’

W10-FastRing

As today it is the first of July I decided to create two new categories on my blog, Windows 10 and Windows Server 2016. At the 29th of July Windows 10 will be officially released so I will use the coming weeks to highlight some of the unique, redesigned functionalities of both the OS as well as the automation features that are available to us. The will be a heavy emphasis on the new and updated functionality of PowerShell 5.0.

As an extra I have attached the download link of the, 4K Hero Wallpaper, the new default wallpaper that is included in the 10159 build. The links are available here:

Windows 10 Build 10159 Released
Whoa! Another PC build!
4K Hero Windows 10 Wallpaper