如果为Powershell初学者提供语句帮助



现在我有一个Powershell脚本,可以在测试路径后启动Lync,然后启动Skype for Business以查看它是否存在。我正在尝试将以下内容添加到一个更大的 if 语句中,以便它将运行 lync 部分,然后仅在 lync 不存在时才运行办公室通信器部分。 我尝试了几种不同的方法,但失败了。谁能帮忙?

if (Test-Path 'C:Program Files (x86)Microsoft Officeoffice15lync.exe'){
Start-Process 'C:Program Files (x86)Microsoft Officeoffice15lync.exe'
} Else {
write-host "Lync is not installed"}

if (Test-Path 'C:Program Files (x86)Microsoft Office Communicator'){
Start-Process 'C:Program Files (x86)Microsoft Office Communicatorcommunicator.exe'
} Else {
write-host "Communicator is not installed"}

你需要将第二个 IF 嵌套在第一个 ELSE 中,如下所示:

if (Test-Path 'C:Program Files (x86)Microsoft Officeoffice15lync.exe')
{
    Start-Process 'C:Program Files (x86)Microsoft Officeoffice15lync.exe'
}
Else
{
   write-host "Lync is not installed"
   if (Test-Path 'C:Program Files (x86)Microsoft Office Communicator')
   {
        Start-Process 'C:Program Files (x86)Microsoft Office Communicatorcommunicator.exe'
   }
   Else 
   {
           write-host "Communicator is not installed"}
   }
}

最新更新