powershelliotwindows-iot-core-10

Run powershell scripts ".ps1 " on windows IoT core devices


I am running Windows IoT core on a gateway, and want to run PowerShell scripts as .ps1 format in the windows iot core device,

I have written a simple PowerShell script to get the storage in a variable and print the variable

$a = Get-PSDrive
echo "$a"

Before that, I have connected my local IoT core device using the PowerShell IDE,

 net start WinRM
 Set-Item WSMan:\localhost\Client\TrustedHosts -Value 192.168.1.104
 Enter-PSSession -ComputerName 192.168.1.104 -Credential administrator 

after this, I got the PowerShell of the windows IoT core device

[192.168.1.104]: PS C:\Data\Users\administrator.MINWINPC\Documents>

Now when I am running a single line of cmdlets like

192.168.1.104]: PS C:\Data\Users\administrator.MINWINPC\Documents>  Get-PSDrive

its working file its giving the output, but when i am trying this -

$a = Get-PSDrive
echo "$a"

This is giving the bellow error -

[192.168.1.104]: PS C:\Data\Users\administrator.MINWINPC\Documents>     $a = Get-PSDrive
echo "$a"
Alias C Cert Env Function HKCU HKLM U Variable WSMan

I need to run a PowerShell scripts in the IoT core device

Thanks for the answer, in the windows system its works just fine

This works perfectly echo with " "

$a = "hi"
echo "about to start infinite loop"
while(1)
{
      echo "$a"
      Start-Sleep -Seconds 1.5
}


PS C:\Users\arnab.h.ghosh> C:\Users\arnab.h.ghosh\Pictures\loop.ps1
about to start infinite loop
hi
hi
hi
hi

Solution

  • You can try with following script:

    $a = Get-PSDrive
    echo $a
    

    Here, $a is a variable to store the result of Get-PSDrive, you can not use quotation marks to echo the variable. Please see Using variables to store objects.