Setting time on Raspberry Pi using just PowerShell

0 votes

I'm running Windows 10 IoT Core on my Raspberry Pi 2 and I need to set its Date and Time to the Date and Time of a local device.
So, I created a variable $dateTime to store the local date and time and I connect to the Pi using the password that I store on another variable $password and Enter-PSSession using a credential object. After that, I try assining the Pi's DateTime through Set-Date = $device using Enter-PSSession. Now that I'm connected I try assigning the remote devices DateTime using Set-Date = $dateTime | Out-String.
I get the following error:
cannot convertvalue "=" to type "System.TimeSpan" error 

Where could I be going wrong?
$dateTime = Get-Date
$password = ConvertTo-SecureString "mypassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("myremotedevice     \Administrator",$password)
Enter-PSSession -ComputerName myremotedevice -Credential $cred
Set-Date = $dateTime | Out-String

powershell raspberry-pi iot windows-10-iot-core

Aug 10, 2018 in IoT (Internet of Things) by Bharani
• 4,660 points
945 views

1 answer to this question.

0 votes

The Enter-PSSession is for interactive sessions, so use this instead:

$dateTime = Get-Date;
$password = ConvertTo-SecureString "mypassword" -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ("myremotedevice     \Administrator",$password);
Invoke-Command -ComputerName myremotedevice -Credential $cred -ScriptBlock {
    Set-Date -Date $using:datetime;
}

And try this if you have multiple executions happening:

$dateTime = Get-Date;
$password = ConvertTo-SecureString "mypassword" -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ("myremotedevice     \Administrator",$password);
$session = New-PsSession -ComputerName -Credential $cred;
Invoke-Command -Session $session -ScriptBlock {
    Set-Date -Date $using:datetime;
}
Invoke-Command -Session $session -ScriptBlock { [...] }
.
.
Disconnect-PsSession -Session $session;

answered Aug 10, 2018 by nirvana
• 3,130 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Running two processes on Raspberry Pi at the same time

I see no reason why it shouldn't ...READ MORE

answered Aug 28, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
1,980 views
0 votes
1 answer

Setting-up a RFID RC522 chip in Raspberry Pi?

First, let me congratulate you on buying ...READ MORE

answered Jul 10, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,643 views
0 votes
1 answer

Connect Android Things based Raspberry Pi 3 to wifi network for the first time!

Hey, I think its alright!  Your Raspberry Pi ...READ MORE

answered Jul 19, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,133 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Connecting GSM Module to Raspberry Pi 2

Hey, just use any 'supported' USB-to-Serial adapter ...READ MORE

answered Nov 22, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
1,019 views
0 votes
1 answer

Disk Management Commands in PowerShell for Windows IoT device

All libraries of the full .Net framework ...READ MORE

answered Nov 26, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,081 views
0 votes
1 answer
0 votes
1 answer

Sending more than 8 byte through UART on Raspberry Pi using Android Things!

So, you can send 234212441325454543595674859764 in ASCII, ...READ MORE

answered Aug 25, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,271 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP