Update Path Environment Variable Using PowerShell In Windows 10 Creators Edition

#Update Path Environment Variable Using PowerShell In Windows 10 Creators Edition

#These are the two PowerShell commands you need to permanently update the Path environment variable in Windows 10 Creators Edition and Windows 10 Anniversary Edition.  If that is all you want to do then you do not need to read further than the following two commands. These commands all work in both PowerShell and PowerShell Direct.

$Old_Path=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name Path).Path #Save old Path variable value
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value ($Old_Path += ';c:\Important Executables') #Append new path to existing path variable

#The Longer Story…

#Setx is the old way to modify registry entries and set environment variables. It still works if needed but PowerShell commands are all I am attempting to use at this point.

#Check mounted drives and filesystems

#You do not need to run the command below. Is just to prove a point about accessing different mount points.

#Run Get-PSDrive to see the drives available in PowerShell.

Get-PSDrive

#▲You will see Env listed under the Name column and Provider is Environment meaning that the environment variables are an actual mounted file system to PowerShell and the same commands you use to manage other filesystems will work when modifying or adding environment variables manually.

#Add c:\Important Executables to the existing environment path for the current session only.

#Disconnecting your PowerShell session loses these changes when you reconnect to a new session. You instead need to update the registry to make the change permanent. There is no output for the following command but you would need to change c:\Important Executables to the directory you would like to include in your system path. This command has no results or confirmation.

$env:Path += ';c:\Important Executables'

#Check current permanent Path variable

#Check the registry key value for the Path variable to see what it is currently set to.  Any changes so far are still not there after running the last command. The path will revert to the results of the command below once you disconnect and reconnect your PowerShell session.

(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name Path).Path|fl

#Get-ItemProperty before updating the registry value.

 

#▲Get-ItemProperty after updating the registry value.

 

#Use Get-Item Env:Path  to get the currently loaded Path environment variable value

Get-Item Env:Path|fl

#$Env:Path also works as a shortcut for Get-Item Env:Path

#$Env:Path after exiting PowerShell and reconnecting again.

#Perserve old path to $Old_Path and a new path to the existing path

#To save the current registry value for combining with the new path or at least have the original value stored in case you screw something up by typing:

$Old_Path=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name Path).Path

#Set registry key to the old registry value combined with the new directory

#Modify HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment|Path properties to include a new directory.

Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value ($Old_Path += ';c:\Important Executables') -Verbose -PassThru|fl

#Delete Environment Variables

#Setting a variable = to an empty string will remove it completely.

$Env:VariableName = ''

#Default Path In Windows 10 Creators Edition

#For reference in case something gets screwed up. This is not a commnad
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\

Enable File And Printer Sharing In Windows 10 Creators Edition Without Using The netsh Command In PowerShell

#Enable File And Printer Sharing In Windows 10 Without Using The netsh Command in PowerShell

#It is as simple as enabling  the pre-configured rule in Windows Firewall to enable File and Printer Sharing in Windows 10 but using netsh is the old fashion way.

#Run this command in an elevated PowerShell prompt and you are done.

Get-NetFirewallRule -DisplayGroup 'File and Printer Sharing'|Set-NetFirewallRule -Profile 'Private, Domain' -Enabled true -PassThru|select Name,DisplayName,Enabled,Profile|ft -a

#The Long Story…

#Allow File and Printer Sharing services through the Windows Firewall to access shared information and to share information of your own. These commands all work in both in PowerShell and PowerShell Direct.

#Get Firewall rules for File and Printer Sharing

#This command shows the individual rules and the network connection profiles that  are explicitly enabled and disabled for the File and Printer Sharing services.

Get-NetFirewallRule -DisplayGroup 'File and Printer Sharing'|select Name,DisplayName,Enabled,Profile|ft -a

#Enable File and Printer Sharing for Private and Domain network profiles

#Enable the  File and Printer Sharing services for the Private and Domain network connection profiles by applying the preconfigured Windows Firewall group rule called File and Printer Sharing by typing this:

Get-NetFirewallRule -DisplayGroup 'File and Printer Sharing'|Set-NetFirewallRule -Profile 'Private, Domain' -Enabled true -PassThru|select Name,DisplayName,Enabled,Profile|ft -a

#▲That is what it looks like under Advanced Sharing Settings when the File and Printer Sharing firewall rule is enabled.

#Set Network Connection Profile to Private.

#I set the variable $InterfaceAlias to automatically query my primary network interface or NIC. The -NlMtuBytes 1500 switch is what makes it work. If you have changed the Maximum Transmission Unit (MTU) from the defaults then this command will need to be modified:

$InterfaceAlias = (Get-NetIPInterface -AddressFamily IPv4 -ConnectionState Connected -NlMtuBytes 1500 -Verbose) #this works for me to automatically identify my nic - mtu 1500 may vary
Set-NetConnectionProfile -InterfaceIndex $InterfaceAlias.ifIndex -Ne

#Disable File and Printer Sharing on all network profiles

Get-NetFirewallRule -DisplayGroup 'File and Printer Sharing'|Set-NetFirewallRule -Enabled false -PassThru|select Name,DisplayName,Enabled,Profile|ft -a

#▲It will look like this when File and Printer Sharing is disabled.

Enable Network Discovery In Windows 10 Without Using the netsh Command In PowerShell

#Enable Network Discovery In Windows 10 Without Using the netsh Command In PowerShell

#It is as simple as enabling  the pre-configured rule in Windows Firewall to enable Network Discovery in Windows 10 but using netsh is the old fashion way.

#Run just this one command in an elevated PowerShell prompt to enable Network Discovery

Get-NetFirewallRule -DisplayGroup 'Network Discovery'|Set-NetFirewallRule -Profile 'Private, Domain' -Enabled true -PassThru|select Name,DisplayName,Enabled,Profile|ft -a

#The Longer Story…

#Enabling the Network Discovery services it what makes the Network icon (formally My Network Places) work properly. These commands all work in both PowerShell and PowerShell Direct.

#Get Firewall rules for Network Discovery

#This command shows the individual rules and the network connection profiles that  are explicitly enabled and disabled for Network Discovery.

Get-NetFirewallRule -DisplayGroup 'Network Discovery'|select Name,DisplayName,Enabled,Profile|ft -a

#Enable Network Discovery for Private and Domain network profiles

#Enable the Network Discovery service for the Private and Domain network profiles by applying the preconfigured Windows Firewall group rule called Network Discovery by typing this:

Get-NetFirewallRule -DisplayGroup 'Network Discovery'|Set-NetFirewallRule -Profile 'Private, Domain' -Enabled true -PassThru|select Name,DisplayName,Enabled,Profile|ft -a

#▲It will look like that in the GUI setup when Network Discovery is enabled.

#Set Network Connection Profile to Private.

Set-NetConnectionProfile -NetworkCategory Private -PassThru

#Disable Network Discovery for all network profiles

#Run this command to disable Network Discovery on all network profiles if you do not wish to keep the service available.

Get-NetFirewallRule -DisplayGroup 'Network Discovery'|Set-NetFirewallRule -Enabled false -PassThru|select Name,DisplayName,Enabled,Profile|ft -a

#▲It will look like that in the GUI setup when Network Discovery is disabled.

Open Elevated PowerShell Prompt Here From Right-Click Context Menu Instead Of Command Prompt Here As Administrator In Windows 10

#Open Elevated PowerShell Prompt Here From Right-Click Context Menu Instead Of Command Prompt Here As Administrator In Windows 10

#Run these commands to enable an elevated Elevated PowerShell Prompt Here also known as PowerShell Here as Administrator when right clicking on a folder in Windows Explorer. These commands all work in both PowerShell and PowerShell Direct.

#Just the code:

New-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas -Verbose -Force|ft -a
Get-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas|Set-ItemProperty -Name '(default)' -Value 'Elevated PowerShell Prompt Here' -Verbose -PassThru|fl
Get-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas|Set-ItemProperty -Name Icon -Value 'C:\\Windows\\System32\\imageres.dll,-78' -Verbose -PassThru|fl
New-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas\command -Verbose -Force|ft -a
Get-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas\command|Set-ItemProperty -Name '(default)' -Value '"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoExit cd "%1"' -Verbose -PassThru|fl

#The Long Story…

#HKCR: does not work in this example and you do not need to mount first. This method accesses the registry directly. Many instructions say to use New-PSDrive to mount HKCR: first and use that convention to access it to do many things but none of that is needed.

#Get-PSDrive will show you what is mounted.

Get-PSDrive

#▲As you can see there is no HKCR:

#Moving on…

#If done properly launching Elevated PowerShell Prompt Here will trigger a UAC prompt. This is normal and good. Create all the keys and values by typing the following commands in order:

New-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas -Verbose -Force|ft -a

Get-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas|Set-ItemProperty -Name '(default)' -Value 'Elevated PowerShell Prompt Here' -Verbose -PassThru|fl

Get-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas|Set-ItemProperty -Name Icon -Value 'C:\\Windows\\System32\\imageres.dll,-78' -Verbose -PassThru|fl

New-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas\command -Verbose -Force|ft -a

Get-Item Registry::HKEY_CLASSES_ROOT\Directory\shell\runas\command|Set-ItemProperty -Name '(default)' -Value '"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoExit cd "%1"' -Verbose -PassThru|fl

#This works when right-clicking only on folders in Windows Explorer and not drives or drive letters.

#Create the User’s file folder (from the Desktop Experience feature) on the Desktop of all new and current users

#Run this to create the User’s file folder (from the Desktop Experience Feature) on the Desktop of all new and current users. After that you will always have a folder nearby to single right-click on to launch an Elevated PowerShell Prompt Here session.

# Since HKLM is mounted already I can use the short path to manipulate the registry entries.

Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel|Set-ItemProperty -Name '{59031a47-3f72-44a7-89c5-5595fe6b30ee}' -Value 0

user folder created with registry change using microsoft powershell should appear on your Desktop after using F5 to refresh or on log off /reboot. Use the commands above to right-click and launch an elevated PowerShell prompt starting with the selected folder as a starting point.

Enable Hyper-V Role In Windows 10 Professional, Enterprise And Education Vs. Android Emulators

#Enable The Hyper-V Role in Windows 10 Professional, Enterprise Or Education Using PowerShell

#If this is the first time, and if if this will be the only time enabling the Hyper-V role in Windows 10, then this PowerShell command is all you need. If you need to switch the Hyper-V services on/off to avoid interference with other hypervisors and without removing the Hyper-V role then download Hyper-V Switch.

#Enable Hyper-V Role Using PowerShell

Enable-WindowsOptionalFeature -Online -FeatureName:Microsoft-Hyper-V -All

#Disable Hyper-V Role Using PowerShell

Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V

#The Long Story…

#Continue reading if you are having issues or are using a conflicting hypervisor or emulator and getting the dreaded Blue Screen of Death.

#Having Issues Enabling Hyper-V Role In Windows 10 Professional, Enterprise Or Education?

Check Requirements

  • Windows 10 Enterprise, Professional, or Education
  • 64-bit Processor with Second Level Address Translation (SLAT)
  • CPU support for VM Monitor Mode Extension (VT-c on Intel CPU’s)
  • Minimum of 4 GB memory

NOTE: The Hyper-V role cannot be installed on Windows 10 Home.

OK so beyond those requirements lies a different issue many are facing with the advent of Android based virtual machines and emulators.

BlueStacks Android Emulator and Andy Android Emulator both crash on load every time, when the Hyper-V role is active.  It looks like both used to work together before the Anniversary Edition update broke the support of Hyper-V and other emulators running at the same time. Here is the bulletin from BlueStacks regarding this issue.

I  want my computer to run everything and work right all the time, so I tried to install x86Android Android Emulator in Hyper-V as an alternative. Once I finally was able to get an older version to work; I found the touchscreen support / controls were unsuitable for my needs. The controls were pure garbage. I may revisit that scenario and try for a more complete configuration but BlueStacks Android Emulator is just so much more user friendly on every level. For now, I switch back and forth between a Hyper-V and a BlueStacks setup.

Here is what I found to switch Hyper-V on and off.  Previously, I was removing the Hyper-V role and adding it again when needed, but a caveat of doing that is the Hyper-V Virtual Switch Manager settings are lost in the process. The settings need to be recreated and reattached to each virtual machine, every time the role is reinstalled. You end up with a lot of orphaned network adapters.


!!!Hyper-V Switch To The Rescue!!!

Calm down. This utility doesn’t allow Hyper-V to run simultaneously with VMWare, VirtualBox or BlueStacks, but this great tool I found at least saves a reboot (it takes two reboots if you add and remove the Hyper-V role). Also, I don’t have to reconfigure Virtual Switch Manager every time I do it. This program automates a bcdedit process to disable Hyper-V without removing the Hyper-V role as part of the process.

Use Hyper-V Switch to toggle Hyper-V support on and off when using other emulators like VirtualBox or Andy Android Emulator to keep it fast and simple. I saved it to my Desktop and edited the executable file to Run as Administrator just to be sure it has the rights needed. You can also single right-click on the executable file or shortcut and then single left-click on Run as Administrator every time.

https://github.com/ygoe/HyperVSwitch – Download from GitHub

http://unclassified.software/apps/hypervswitch – Hyper-V Switch Website


#Enable The Hyper-V Role Using PowerShell manually or for the first time

#For the first and if the only time enabling the Hyper-V role then the command  below is all you need.

Enable-WindowsOptionalFeature -Online -FeatureName:Microsoft-Hyper-V -All

#Enable Hyper-V and all features.

Enable-WindowsOptionalFeature -Online -FeatureName:Microsoft-Hyper-V -All

#Type y and press Enter


#Disable The Hyper-V Role Using PowerShell

Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V

#Disable Hyper-V and all features

Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V#Type y and press Enter


Manually Enable Hyper-V From The GUI

Windows Key-R to bring up the Run box.

Type optionalfeatures.exe and single left-click OK to execute (just means to run) optionalfeatures.exe. This method actually allows for more control of the Hyper-V installation since you can deselect unneeded features. For example, some people may not have any need for the Hyper-V Module for Windows PowerShell module if they don’t use PowerShell  or PowerShell Direct to administer any virtual machines.

Single left-click to select the Hyper-V option. Single left-click the Plus sign to expand if you need to select or deselect any of the default features. I use all the Hyper-V features so PowerShell for this installation works just fine for me. The end goal is to avoid moving my mouse as much as possible.