检查powershell脚本是否已加载 - 环境文件

时间:2015-01-28 12:30:01

标签: powershell

我有几个正在加载environment.ps1文件的powershell脚本。

现在我已经创建了一个" install.ps1"在哪里我"链接"在那些我需要的powerhshell脚本中。如何检查environment.ps1文件是否已加载?

###############################################################################
# INSTALL SCRIPT  
###############################################################################

function LoadFiles
{
param([string]$fileName = "unknown.ps1")

Try
{
     . .\$fileName
}
Catch [system.exception]
{
    Write-Host "Problems accessing "+$fileName +" file, check the file location" -ForegroundColor Red
    Break
}
}


LoadFiles "Environment.ps1"             #environment.ps1, variables, Add-    PSSnapin
LoadFiles "MySiteWebApp.ps1"            #this file also loads environemnt
LoadFiles "CreateCTHUB.ps1"             #this file also loads environment

1 个答案:

答案 0 :(得分:3)

为什么不在environment.ps1中创建变量(例如$ EnvVarsImported)并将其值设置为$ true?然后,您可以假设在导入脚本(install.ps1)中成功检查该变量是否存在时,已导入该脚本中的所有函数和变量。

相关问题