Change the timezone on a Server 2016 Nano Server

This article will show you how to change the local time zone on a Windows Server 2016 Nano Server TP4.

To complete this task, I’ll use built-In utility Tzutil.exe which Is already loaded into the Nano server.

To change the time Zone create a remote PowerShell Session to your Nano Server.

Once you logged In check the current timezone with the command below:

tzutil.exe /g

To view all available timezones type:

Tzutil.exe /I

To change the TimeZone type:

tzutil.exe /s "AUS Eastern Standard Time"

Office 2016 Batch file activate

@echo off
C:

REM Check if Office16 has been activated previosuly
IF EXIST "C:\Windows\Office16Activation\" (
	Echo Already Activated

	) ELSE (
	mkdir C:\Windows\Office16Activation
	IF EXIST "C:\Program Files (x86)\" (
		REM 64Bit Machine
		REM Check if Office16 key has been installed 
		IF NOT EXIST "C:\Windows\Office16Activated\Key" (
			cscript "C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS" /inpkey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
			mkdir C:\Windows\Office16Activation\KeyInstalled
			)
		REM Check if Office16 key has been activated
		IF NOT EXIST "C:\Windows\Office16Activated\Act" (
			cscript "C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS" /act
			mkdir C:\Windows\Office16Activation\Activated
			)
		) ELSE (
		REM 64Bit Machine
		REM Check if Office16 key has been installed 
		IF NOT EXIST "C:\Windows\Office16Activated\Key" (
			cscript "C:\Program Files\Microsoft Office\Office16\OSPP.VBS" /inpkey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
			mkdir C:\Windows\Office16Activation\KeyInstalled
			)
		REM Check if Office16 key has been activated
		IF NOT EXIST "C:\Windows\Office16Activated\Act" (
			cscript "C:\Program Files\Microsoft Office\Office16\OSPP.VBS" /act
			mkdir C:\Windows\Office16Activation\Activated
			)
		)
		)

Windows 10 SysPrep Woes

New image created at a school I support, fully updated, all apps installed tested and working. Come to sysprep the image and BOOM – “Sysprep will not run on a upgraded OS.”

It can now after this quick “fix” –

Remove this KEY from the Registry:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\Setup\Upgrade

Remove this REG_DWORD from the Registry:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\Setup\Upgrade

Set this REG_DWORD from the Registry:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\Setup\Status\SysprepStatus\CleanupState [Set Hexadecimal Value: 7]

Run this command as Administrator:
slmgr /dli

So then I though great sorted, NOPE! Windows 10 SysPrep brings in AppX Applications, they now have to be removed before sysprep also

To resolve this issue, remove the package for the user who’s running sysprep, and also remove the provisioning. To do this, follow these steps.

Note To prevent Windows Store from updating apps, unplug the Internet connection or disable Automatic Updates in Audit mode before you create the image.

  1. Run the Import-Module Appx PowerShell cmdlet.
  2. Run Import-Module Dism.
  3. Run Get-AppxPackage -AllUser | Where PublisherId -eq 8wekyb3d8bbwe | Format-List -Property PackageFullName,PackageUserInformation.

    Notes

    • In the output of this last cmdlet, check the users for whom the package is showing up as Installed. Delete these user accounts from the reference computer, or log on to the computer by using these user accounts. Then, run the cmdlet in step 4 to remove the Appx package.
    • This command lists all packages that were published by Microsoft and installed by any user of that reference computer. Because the computer is to be sysprepped, we assume that these user profiles no longer require the package.
    • If you have manually provisioned apps that belong to other publishers, run the following command to list them:

      Get-AppxPackage -AllUser | Format-List -Property PackageFullName,PackageUserInformation

  4. Run Remove-AppxPackage -Package <packagefullname>.
  5. Remove the provisioning by running the following cmdlet:

    Remove-AppxProvisionedPackage -Online -PackageName <packagefullname>

If you try to recover from an update issue, you can reprovision the app after you follow these steps.

Note The issue does not occur if you are servicing an offline image. In that scenario, the provisioning is automatically cleared for all users. This includes the user who runs the command.

PS – Read remote mySql Data from Powershell

#Load the .net MySql DLL
[system.reflection.Assembly]::LoadFrom("C:\MySql.Data.dll")
Clear

#Create the connection object
$myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection

#Create the ConnectionString
$myconnection.ConnectionString = "database=my_database;server=my.sql.server.com;Persist Security Info=false;user id=my_database_user;pwd=my_database_pwd"

$myconnection.Open()

$command = $myconnection.CreateCommand()
$command.CommandText = "SELECT * FROM `Tablet` WHERE `ID` = '1'";

$dataSet = New-Object System.Data.DataSet

$reader = $command.ExecuteReader()

while
($reader.Read()) {
  for ($i= 0; $i -lt $reader.FieldCount; $i++) {
    write-host $reader.GetValue($i).ToString()
  }
}

$myconnection.Close()