使用json内容启动进程问题
js文件的内容。Program.js使用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
[
{ "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
}
}
是的,我应该清除数组名。谢谢,这解决了我的问题