Hello fellows of Win10 IoT Development!

I want to write a program that sets the time of my Raspberry Pi 3 with Windows 10 IoT so my timestamps will be correct.

I am generating an SSH Connection via Renci.SshNet and codes like those do work perfectly fine:

Renci.SshNet.SshClient client = new SshClient(IP, Username, PW);
client.RunCommand("TZUTIL /s \"W.Europe Standard Time\"");
client.RunCommand("shutdown /r /t 0");

But it is impossible for me to pass the Set-Date command:

I tried all of the following:
// Manual
client.RunCommand("Set-Date " + ((char)34) + "08.06.2016 14:08:45" + ((char)34));
client.RunCommand("Set-Date \"10/3/2015 2:00PM\"");
// Dynamic
System.DateTime dateTime;
dateTime = System.DateTime.Now.AddHours(2);
String datestr = dateTime.ToString();
client.RunCommand("set-date \"" + datestr + "\"");

There is a guide "How to connect via Shell Commands" and the command Set-Date "08.06.2016 14:31:00" works perfectly fine, but the same Code doesn't pass anything in the program...

Im am glad for any help!

Note: Related to How to set system time in Windows 10 IoT?

  • "it is impossible for me to pass the Set-Date command" What specifically happens when you try? Do you get any error messages? What do the error message say? – Kenster Jun 8 '16 at 13:41
  • What is your datestr looks like? Is it the same format with 08.06.2016 14:08:45? Have you ever tried to format it with custom format specifiers and a specific culture instead? – Soner Gönül Jun 8 '16 at 13:55
  • @Kenster There is no error message it just stops there until the Timer invokes the method again. It just doesn't set the time on my Raspberry neither commits the "set-date" Command and all commands after that. @SonerGönül Specific Culture same issue: DateTime dt = DateTime.Now; Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); CultureInfo ci = new CultureInfo("de-DE"); client.RunCommand("Set-Date \"" + dt.ToString(ci) + "\""); Any ideas what else it might be? – Kyagos Jun 9 '16 at 7:53

You are mixing Windows Commands and PowerShell Commands.

When you SSH to Windows 10 IoT Core, you are connected to the Windows Command Prompt and can execute Windows Commands such as shutdown.exe.

Set-Date is a PowerShell Cmdlet so must be executed from PowerShell. You can execute PowerShell commands from the Windows Command Prompt like this: PowerShell "Set-Date ""6/16/2016 11:00PM"""

In your case the code for the SSH client would be:
var command = "PowerShell \"Set-Date \"\"6/16/2016 11:00PM\"\"\""; client.RunCommand(command);

| improve this answer | |
  • Thx! Unfortunately the connection still doesn't push it Did you mean that some PowerShell Commands aren't supported in WC Promts? This may lead to the conclusion that the resource from Rencii is not the best way to start for Set-Date via C# Program – Kyagos Jun 20 '16 at 13:38

Your Answer

