Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用json内容启动进程问题_Json_Powershell - Fatal编程技术网

使用json内容启动进程问题

使用json内容启动进程问题,json,powershell,Json,Powershell,js文件的内容。Program.js [ { "ProgramName":"Chrome", "FilePath":"\"\\\\PCNAME\\c$\\Users\\USERNAME\\Desktop\\Work Notes\\Programs\\Google\\ChromeSetup.exe\""}, { "ProgramName":"Notepad ++", "FilePath":"\"\\\\PCNAME\\c$\\Users\\USERNAME\\Des

js文件的内容。Program.js

[
        { "ProgramName":"Chrome", "FilePath":"\"\\\\PCNAME\\c$\\Users\\USERNAME\\Desktop\\Work Notes\\Programs\\Google\\ChromeSetup.exe\""},
        { "ProgramName":"Notepad ++", "FilePath":"\"\\\\PCNAME\\c$\\Users\\USERNAME\\Desktop\\Work Notes\\Programs\\Notepad ++\\npp.7.3.3.Installer.exe\"" }

    ]
我不擅长解释,但我正在尝试获取json文件每一行的
程序名
,以及该名称是否与
$computernames
数组中的一个名称匹配。然后使用
程序名
的相应
文件路径
运行安装程序。 这就是我目前所拥有的

$json = (Get-Content "\\PCNAME\c$\Users\USERNAME\Desktop\Powershell\SCCM\Softwareinstaller\Program.js" -Raw) | ConvertFrom-Json
$computerNames = "Chrome","Office","Google Earth","Adobe Pro","GoToMeeting Opener"
foreach ($thing in $json) 
{
    foreach ($thing2 in $json)
    {
        if ($computernames -contains $Thing2.programname)
        {
            Start-Process -filepath $thing.FilePath -wait
        }
    }

}

我计划在json文件中添加更多内容,因此不只是查找行号的方法将是首选。

我不确定为什么会有
thing2
-循环。JSON是一个项目数组。运行循环,查看名称是否在
$computerNames
-数组中(顺便说一句,名称不正确),然后执行。尝试:

$json = (Get-Content "\\PCNAME\c$\Users\USERNAME\Desktop\Powershell\SCCM\Softwareinstaller\Program.js" -Raw) | ConvertFrom-Json
$computerNames = "Chrome","Office","Google Earth","Adobe Pro","GoToMeeting Opener"

foreach ($thing in $json) 
{
    if ($computernames -contains $thing.ProgramName)
    {
        Start-Process -FilePath $thing.FilePath -wait
    }

}

是的,我应该清除数组名。谢谢,这解决了我的问题