Access Registry with PowerShell

Working with Registry is very similar to working with files and folders with PowerShell.
Set-Location cmdlet can set the current working location to registry.

PS C:\Windows\system32> Set-Location Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER
PS Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER>

The registry provider’s full name is Microsoft.PowerShell.Core\Registry, but this can be shortened to just Registry.

PS C:\Windows\system32> Set-Location Registry::HKEY_CURRENT_USER
PS Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER>

In addation, PowerShell has two pre-defined registry ‘drives’:
HKLM for HKEY_LOCAL_MACHINE
HKCU for HKEY_CURRENT_USER

PS C:\Windows\system32> Set-Location HKCU:
PS HKCU:\>

However, other registry roots are not defined.

PS HKLM:\> Set-Location HKCR:
Set-Location : 드라이브를 찾을 수 없습니다. 이름이 'HKCR'인 드라이브가 없습니다.
위치 줄:1 문자:1
+ Set-Location HKCR:
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (HKCR:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

PS HKLM:\>

You can define other roots by yourself with New-PSDrive cmdlet.

PS HKLM:\> New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
Name      Used (GB)      Free (GB)    Provider    Root    CurrentLocation
----      ---------      ---------    --------    ----    ---------------
HKCR                                            Registry  HKEY_CLASSES_ROOT

PS HKLM:\> Set-Location HKCR:
PS HKCR:\>

Modify File Time Stamps using PowerShell

Usages:
(Get-Item [filename]).CreationTime = [date/time]
(Get-Item [filename]).LastAccessTime = [date/time]
(Get-Item [filename]).LastWriteTime = [date/time]

PS C:\> (Get-Item .\test.txt).LastAccessTime = Get-Date
→ This command converts 'last access time' of 'test.txt' to current date and time

PS C:\> (Get-Item .\christmas.tree).LastWriteTime = '2016-12-25 AM0:00'
→ This command converts 'last write time' of 'christmas.tree' to specific date and time
Batch Processing with ForEach:
Get-ChildItem | ForEach-Object { $_.LastWriteTime = Get-Date }

PS C:\> Get-ChildItem | ForEach-Object { $_.LastWriteTime = Get-Date }
→ This command converts 'last write time' to current date and time of all files in working directory

PS C:\> $i = 0; Get-ChildItem | ForEach-Object { $_.LastWriteTime = (Get-Date).AddDays(-1).AddMinutes($i++) }
→ This command converts 'last write time' to yesterday with increasing minutes

Turn on/off mobile hotspot on windows 10 via powershell

To turn on mobile hotspot:
PS C:\> [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]::CreateFromConnectionProfile([Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime]::GetInternetConnectionProfile()).StartTetheringAsync()↵


To turn off mobile hotspot:
PS C:\> [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]::CreateFromConnectionProfile([Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime]::GetInternetConnectionProfile()).StopTetheringAsync()↵