【问题标题】:Run powershell scripts ".ps1 " on windows IoT core devices在 Windows IoT 核心设备上运行 powershell 脚本“.ps1”
【发布时间】:2019-08-21 05:10:06
【问题描述】:

我在网关上运行 Windows IoT 核心,并希望在 Windows 物联网核心设备中以 .ps1 格式运行 PowerShell 脚本,

我编写了一个简单的 PowerShell 脚本来获取变量中的存储并打印变量

$a = Get-PSDrive
echo "$a"

在此之前,我已经使用 PowerShell IDE 连接了我的本地 IoT 核心设备,

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

在这之后,我得到了windows IoT核心设备的PowerShell

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

现在,当我运行单行 cmdlet 时,例如

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

它的工作文件给出了输出,但是当我尝试这个时 -

$a = Get-PSDrive
echo "$a"

这是给出以下错误 -

[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

我需要在 IoT 核心设备中运行 PowerShell 脚本

感谢解答,在windows系统下运行正常

这与“”完美呼应

$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

【问题讨论】:

    标签: powershell iot windows-iot-core-10


    【解决方案1】:

    您可以尝试以下脚本:

    $a = Get-PSDrive
    echo $a
    

    这里$a是一个变量,用来存储Get-PSDrive的结果,不能用引号来回显变量。请参阅Using variables to store objects

    【讨论】:

    • 已在帖子中回复
    • @ArnabGhosh,在您更新的帖子中,变量 $a 被设置为 const 字符串,但 Get-PSDrive 返回一个对象。这是不同的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多