Generate report for WLAN usage

I just discovered this cool WLAN report functionality while looking at the docs for netsh.
The command is not available on my Windows 7 machines so presumably it’s new for Windows 8 and later.

Please note that the command prompt must be run as admin.

netsh wlan show wlanreport

The command generates a nice looking HTML report and saves it to C:\ProgramData\Microsoft\Windows\WlanReport\wlan-report-latest.html

Click on the picture below for an example report

Unfortunately it doesn’t seem to be supported when using netsh on a remote client.

 

MS Cheatsheet

List TCP/IP interfaces on remote computer

netsh -r "hostname" interface ipv4 show interfaces


Get Windows OEM license key

wmic path SoftwareLicensingService get OA3xOriginalProductKey


List environment variables

set

Filter output

set prog


Install .NET Framework 3.5 on Windows 10

Online version:
DISM.EXE /Online /Add-Capability /CapabilityName:NetFx3~~~~

Offline version (requires .cab installer for the .NET framework):
DISM.EXE /Online /Add-Package /PackagePath:C:\Temp\microsoft-windows-netfx3-ondemand-package.cab


Kill a non responding task from command prompt

taskkill /F /IM taskname.exe

/F = Force kill (ignores any prompts etc)

/IM = Image Name (name of process)


Generate WLAN report (run as admin)

netsh wlan show wlanreport

» See an example report here


List all server shares on local domain network

net view /all /domain:company.com


Message (aka net send)

msg /server:hostname username

Example:

msg /server:pc01 johndoe


List all local MAC addresses

getmac /v


Map network share

net use x: \\server\share /user:domain\username password


Remote sysinfo

msinfo32 /computer hostname


See uptime (and more)

net stats srv

if not available, use

net stats workstation


Show Domain Controllers in domain

nltest /dclist:example.com


Set Environment variable on remote computer

setx /s hostname /u domain\user /p pw variable value

Example:

setx /s PC1234 /u itdb\kek /p 123456 JAVA_HOME "C:\Program Files\Java\jre1.8.0_73"


See Windows license expiration information

slmgr /xpr

Alternatively run slmgr /dli for detailed information about your Windows license

For remote computers: slmgr hostname username password /dli


Useful Windows utilities which you can start from the RUN prompt

  • lusrmgr.msc (Local Users Management)
  • sysdm.cpl (System Properties)
  • appwiz.cpl (Programs & Features)
  • eventvwr (Event Viewer)
  • compmgmt.msc (Computer Management)
  • printmanagement.msc (Print Management)
  • devmgmt.msc (Device Management)
  • services.msc (Services)
  • taskschd.msc (Task Scheduler)

 

This post will be continually updated with useful tips for remote troubleshooting and various tools for Microsoft environments

 

Related posts:

CRON Cheatsheet

Powershell Snippets

Linux Cheatsheet

 

Create a su command for Windows Command Prompt

As an IT tech I often have to open my command prompt as my domain administrator user which has administrator access on remote computers. I always forgets to right-click cmd and choose “Run as …” so I figured out a little shortcut for those times to mimic the su function in Linux.

Please note this won’t turn your currently open command prompt into an elevated one, it will just run a new cmd.exe process as the user you need.

Open an elevated command prompt and change directory to %windir%\system32 and run this command:

echo runas /user:domain\username "cmd" > sudo.bat

Now you can type “sudo” wherever (in your Run window or an existing cmd prompt) and it will prompt you for the password and open a new cmd window with the pre-defined user.

Task Manager for remote computer

It’s not possible to run the Task Manager GUI on a remote computer, but using the tasklist cmdlet you’ll be able to retrieve all running processes in all sessions (user processes, services, etc)

The command is as easy as:

tasklist /S remotehost

Remember you will need local administrator access for the remote computer (i.e. domain admin). Then you can either start cmd.exe as domain admin, or add the credentials to the tasklist command:

tasklist /S remotehost /U domain\username /P password

Output will look like:

mtsc.exe blocks Alt Gr

From time to time my Alt Gr button seems to stop working, which I use for several special characters like @.

Turns out the problem is related to the process mstsc.exe (Microsoft Windows Remote Desktop).

Solution: Close any RDP windows you have open (no need to logout, just close them). Voila, Alt Gr works as intended again. Now you can reopen them and hope it doesn’t happen again.

You should also be aware of the temporary solution: Pressing CTRL + ALT is the same as Alt Gr – in case you can’t close the current RDP windows for any reason.

This minor, yet very infuriating issue, has been present at my computer(s) for several years, both Windows 7 and Windows 10.

Add custom scripts to Powershell user scope

Today I had to google how to find out my Powershell version. How fucked up is that. Luckily 1680 other people wondered the same and appreciated this answer: http://stackoverflow.com/questions/1825585/determine-installed-powershell-version

Turns out the command is: (ignore PS C:\>, that’s just to indicate a Powershell)

PS C:\> $PSVersionTable.PSVersion

No way I’m going to remember that. Luckily, StackOverflow user @ADTC mentioned he made a function to output the version.
Open notepad and write the function to the file specified from the $profile path.

PS C:\> notepad $profile

Insert the function:

function psver { 
    $PSVersionTable; 
    $PSVersionTable.PSVersion 
}

Reload Powershell by running

PS C:\> . $profile

Now you can enter psver to output the version. Beautiful!

If you got an error when running notepad $profile that the file can’t be found, then simply enter $profile in your Powershell window to output the path and create the file manually in Windows Explorer.

Can’t move file – Error 0x800401E5: No object for moniker

How we suddenly got 0x800401E5 errors

Some time ago we changed the desktop folder location for every user from C:\Users\<name>\Desktop to X:\Desktopwith a new group policy rule. This apparantly led to some complications for a few users because the local Windows registry didn’t update the paths somehow. Luckily it only affected a few users so we found a manual workaround.

Fix by using regedit or push out to users with GPO

Open regedit and navigate to the following two locations:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders

Change the Desktop value to correct folder. Remember to do it in both locations.

Simple Robocopy backup script

Robocopy syntax to copy all NEW or EDITED files from source to destination dir:

robocopy "%src%" "%dest%" /E /W:1 /R:1 /XC /log+:"robocopy_log.txt"

Description of the parameters:

  • /E = Copies subdirectories. Note that this option includes empty directories. If you wish to exclude empty directories, use /S.
  • /W:1 = Specifies the wait time between retries, in seconds. The default value of N is 30 (wait time 30 seconds).
  • /R:1 = Specifies the number of retries on failed copies. The default value of N is 1,000,000 (one million retries).
  • /XC = Excludes changed files.
  • /log+: = Writes the status output to the log file (appends the output to the existing log file).

Windows batch script to setup a scheduled task to run the robocopy command:

@echo off
title Robocopy Backup
echo.
echo Initial configuration for automatic backup with Robocopy + Task Scheduler
echo.

echo Step 1 - setup Robocopy:
echo.
set /p src=Backup FROM dir: 
set /p dest=Backup TO dir: 
(
echo cd %userprofile%\Desktop
echo robocopy "%src%" "%dest%" /E /W:1 /R:1 /XC /log+:"robocopy_log.txt"
)> %userprofile%\robocopy.bat

echo.
echo Step 2 - setup Task Scheduler:
echo.
schtasks /create /tn "Robocopy Backup" /tr "%userprofile%\robocopy.bat" /SC HOURLY
echo.
echo Done
echo.

pause

Copy & paste the text into a text editor and save it as a .bat file to make it executable.

When running this script you will setup a scheduled task which runs the robocopy.bat file every hour. Really great and time-saving if you work in a local folder on your C drive and wish to periodically take incremental backups to a network storage for instance.

Map network share without being on domain

Windows

Please note you must have access to a user account with NTFS permissions to access the file share (unless it’s open to everyone).

  • Open command prompt
  • Type the following command:
    net use x: \\server\share /user:domain\username password

Example:
net use y: \\itdb1\home /user:itdb\kek 123456

If the share is open for everyone, you can dismiss the user arguments:
net use y: \\itdb1\home

Keep in mind that if you already are on the domain and try to map a network share with another user than you’re currently logged in with, you will see the error message:

System error 1219 has occured.

Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.

Linux

Linux can also access NTFS mounts. Run the following commands in your terminal:

  • Create a folder which will be used for connecting to the share:
    $ sudo mkdir /mnt/ShareName
  • Mount the network share to your folder:
    • Without user authentication:
      $ sudo mount -t cifs //server/share /mnt/ShareName
    • With user authentication:
      $ sudo mount -t cifs -o username=itdb\kek,password=123456 //itdb1/home /mnt/ShareName