在powershell中使用文件的相对路径

时间:2017-08-14 08:23:28

标签: powershell

我正在使用PowerShell文件。我在同一文件夹中有一个文件,路径可以更改,但文件夹保持不变。

如何使用相对路径,所以脚本没有变化?

Param([string]$servername, [string]$path)
#Param([string]$instance)

#$path1="d:\sysdba\"
#$path2= $path1 "+" $path

try {
    Invoke-Expression -Command "d:\sysdba\File_Creation.ps1 $servername"
} catch {
    Write-Host -BackgroundColor Red -ForegroundColor White "Fail"

    $errText =  $Error[0].ToString() 

    if ($errText.Contains("network-related")) {
        Write-Host "Connection Error. Check server name, port, firewall."
    }
    Write-Host $errText 
    continue 
}

而不是

Invoke-Expression -Command "d:\sysdba\File_Creation.ps1 $servername"

我想像.\file_creation.ps1一样使用,但它无效。

0 个答案:

没有答案