if语句帮助powershell初学者
If statement assistance for powershell beginner
现在我有一个 powershell 脚本可以启动 Lync,然后在测试路径后启动 Skype for business 以查看它是否存在。我正在尝试将以下内容添加到更大的 if 语句中,这样它将 运行 lync 部分,然后如果 lync 不存在则仅 运行 office communicator 部分。我已经尝试了几种不同的方法但都失败了。有人可以帮忙吗?
if (Test-Path 'C:\Program Files (x86)\Microsoft Office\office15\lync.exe'){
Start-Process 'C:\Program Files (x86)\Microsoft Office\office15\lync.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 Communicator\communicator.exe'
} Else {
write-host "Communicator is not installed"}
您需要将第二个 IF 嵌套在第一个 IF 的 ELSE 中,如下所示:
if (Test-Path 'C:\Program Files (x86)\Microsoft Office\office15\lync.exe')
{
Start-Process 'C:\Program Files (x86)\Microsoft Office\office15\lync.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 Communicator\communicator.exe'
}
Else
{
write-host "Communicator is not installed"}
}
}
现在我有一个 powershell 脚本可以启动 Lync,然后在测试路径后启动 Skype for business 以查看它是否存在。我正在尝试将以下内容添加到更大的 if 语句中,这样它将 运行 lync 部分,然后如果 lync 不存在则仅 运行 office communicator 部分。我已经尝试了几种不同的方法但都失败了。有人可以帮忙吗?
if (Test-Path 'C:\Program Files (x86)\Microsoft Office\office15\lync.exe'){
Start-Process 'C:\Program Files (x86)\Microsoft Office\office15\lync.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 Communicator\communicator.exe'
} Else {
write-host "Communicator is not installed"}
您需要将第二个 IF 嵌套在第一个 IF 的 ELSE 中,如下所示:
if (Test-Path 'C:\Program Files (x86)\Microsoft Office\office15\lync.exe')
{
Start-Process 'C:\Program Files (x86)\Microsoft Office\office15\lync.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 Communicator\communicator.exe'
}
Else
{
write-host "Communicator is not installed"}
}
}