CMD Settings (Various) - Neilitlib/MSP-Simple-Commands GitHub Wiki

Temporarily Set/Associate a Path with a Drive Letter

CLI

subst Z: C:\

Reverts changes on Reboot. Very useful for user-apps when user profiles are redirected to a server, but the user app needs to update and it points to C (which is actually Z for example).

The subst command in Windows is used to associate a path with a drive letter, creating a virtual drive. When you run the command subst Z: C:\, it creates a virtual drive Z: that points to the root directory of the C: drive. Essentially, Z: will act as a shortcut to C:\. If you navigate to Z:, you’ll see the contents of C:\ as if you were directly accessing the C: drive. This can be useful for simplifying access to frequently used directories as well.

Set Desktop Background

PS

SET at login

$Data=@{WallpaperURL="https://wallpapersok.com/images/hd/pop-star-rick-astley-in-concert-th6vqytajjixfuqj.jpg";LockscreenURL="https://wallpapersok.com/images/hd/pop-star-rick-astley-in-concert-th6vqytajjixfuqj.jpg";DownloadDirectory="C:\temp";RegKeyPath='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP';StatusValue="1"};$WallpaperDest=$($Data.DownloadDirectory+"\Wallpaper."+($Data.WallpaperURL-replace".*\.(\w+)$",'$1'));$LockscreenDest=$($Data.DownloadDirectory+"\Lockscreen."+($Data.LockscreenURL-replace".*\.(\w+)$",'$1'));New-Item-ItemType Directory-Path $Data.DownloadDirectory-ErrorAction SilentlyContinue;Start-BitsTransfer-Source $Data.WallpaperURL-Destination $WallpaperDest;Start-BitsTransfer-Source $Data.LockscreenURL-Destination $LockscreenDest;New-Item-Path $Data.RegKeyPath-Force-ErrorAction SilentlyContinue|Out-Null;New-ItemProperty-Path $Data.RegKeyPath-Name 'DesktopImageStatus'-Value $Data.StatusValue-PropertyType DWORD-Force|Out-Null;New-ItemProperty-Path $Data.RegKeyPath-Name 'LockScreenImageStatus'-Value $Data.StatusValue-PropertyType DWORD-Force|Out-Null;New-ItemProperty-Path $Data.RegKeyPath-Name 'DesktopImagePath'-Value $WallpaperDest-PropertyType STRING-Force|Out-Null;New-ItemProperty-Path $Data.RegKeyPath-Name 'DesktopImageUrl'-Value $WallpaperDest-PropertyType STRING-Force|Out-Null;New-ItemProperty-Path $Data.RegKeyPath-Name 'LockScreenImagePath'-Value $LockscreenDest-PropertyType STRING-Force|Out-Null;New-ItemProperty-Path $Data.RegKeyPath-Name 'LockScreenImageUrl'-Value $LockscreenDest-PropertyType STRING-Force|Out-Null

Revert Changes

$Data=@{DownloadDirectory="C:\\temp";RegKeyPath='HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PersonalizationCSP'};Remove-Item-Path $Data.DownloadDirectory-Recurse-Force-ErrorAction SilentlyContinue;Remove-ItemProperty-Path $Data.RegKeyPath-Name 'DesktopImageStatus'-ErrorAction SilentlyContinue;Remove-ItemProperty-Path $Data.RegKeyPath-Name 'LockScreenImageStatus'-ErrorAction SilentlyContinue;Remove-ItemProperty-Path $Data.RegKeyPath-Name 'DesktopImagePath'-ErrorAction SilentlyContinue;Remove-ItemProperty-Path $Data.RegKeyPath-Name 'DesktopImageUrl'-ErrorAction SilentlyContinue;Remove-ItemProperty-Path $Data.RegKeyPath-Name 'LockScreenImagePath'-ErrorAction SilentlyContinue;Remove-ItemProperty-Path $Data.RegKeyPath-Name 'LockScreenImageUrl'-ErrorAction SilentlyContinue;

Explanation:

  • Registry Path Check: Added a check to ensure the registry path exists before attempting to set the wallpaper.
  • Direct Application: Applies the wallpaper setting for the current user directly after modifying the registry for all users.

Note:

  • Ensure you run the script in PowerShell with administrative privileges.
  • This script sets the wallpaper for all user profiles and applies it for the current user.

Set IP & DNS

- Set Static IP

CLI

netsh interface ip set address "Ethernet 2" static 192.168.50.101 255.255.255.0 192.168.0.1

This sets the "Ethernet 2" adapter to a static ip / mask / gateway of: 192.158.50.101 / 255.255.255.0 / 192.168.0.1

- Set Static DNS

netsh interface ip add dns "Ethernet 2" 192.168.50.5

netsh interface ip add dns "Ethernet 2" 8.8.8.8 index=2

This sets the "Ethernet 2" adapter to use a local IP as the Domain Name Server such as the office's main server, and google as a backup


- Set Dynamic IP via DHCP

netsh interface ip set address "Ethernet 2" dhcp"

- Set Dynamic DNS via DHCP

netsh interface ip set dns "Ethernet 2" dhcp

Set IPv6 On-Off

CLI

powershell -command "Disable-NetAdapterBinding -Name "*" -ComponentID ms_tcpip6"

powershell -command "Enable-NetAdapterBinding -Name "*" -ComponentID ms_tcpip6"


Here’s a breakdown:

  1. powershell -command: This part of the command tells your system to execute the following string as a PowerShell command.
  2. Disable-NetAdapterBinding || Enable-NetAdapterBinding: This is a cmdlet in PowerShell that disables || enables a binding to a network adapter.
  3. -Name "*": This parameter specifies the network adapter(s) to be modified. The asterisk (*) is a wildcard character that represents all network adapters.
  4. -ComponentID ms_tcpip6: This parameter specifies the ID of the component to be disabled. The ID ms_tcpip6 corresponds to the IPv6 protocol.

Set Power Plans to Awake

CLI

  • Useful for keeping the computers awake on wall-power for remote support.

POWERCFG -change -hibernate-timeout-ac 0 && POWERCFG -change -standby-timeout-ac 0

Most MSPs will benefit from this 1st suggested command, it prevents hibernation and standby if plugged in/charging


  • POWERCFG -Change -monitor-timeout-ac 60
  • POWERCFG -CHANGE -monitor-timeout-dc 15
  • POWERCFG -CHANGE -disk-timeout-ac 45
  • POWERCFG -CHANGE -disk-timeout-dc 15
  • POWERCFG -CHANGE -standby-timeout-ac 30
  • POWERCFG -CHANGE -standby-timeout-dc 10
  • POWERCFG -CHANGE -hibernate-timeout-ac 15
  • POWERCFG -CHANGE -hibernate-timeout-dc 5

The commands are used to adjust power settings on a Windows system.

  • They set the time of inactivity (no user input) after which certain actions are taken, such as turning off the monitor or hard disk, or putting the system into standby or hibernate mode.
  • The settings differ based on whether the system is running on AC power (plugged in) or DC power (battery).
  • Changes may require a system restart and can be overridden by other settings or policies.

Set Remote Desktop On-Off

CLI

- Change Listening Port from Default 3389

Use a different port than the default - you should avoid using the default port for better security

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d 58123 /f

Now you have to specify the port of 58123 when connecting

- Enable Remote Desktop for a machine

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f

netsh advfirewall firewall set rule group="remote desktop" new enable=Yes

- Disable Remote Desktop for a machine

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 1 /f

netsh advfirewall firewall set rule group="remote desktop" new enable=No

Set Win10 or Win11 R-Click Menu

CLI

  • Only applies to Windows 11 machines

- Enable W10 Style Right Click Menu in W11

reg.exe add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /f /ve

Brings back the Classic Right Click menu like W10

- Enable Default W11 Right Click Menu

reg.exe delete "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}" /f

Undoes changes from the command above and restores the default W11 Right Click Menu


Classic/Windows 10 Style (Left)

Default Windows 11 Style (Right)

image