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

在powershell中使用文件的相对路径,powershell,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 $s

我正在使用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"

我想使用like
\file\u creation.ps1
但它不起作用。

作为旁注:避免调用表达式。它几乎总是错误的工具。在您的情况下,应该改用call操作符:
和“$PSScriptRoot\File\u Createion.ps1”$servername
。作为旁注:避免
调用表达式
。它几乎总是错误的工具。在您的情况下,应该使用call操作符:
&“$PSScriptRoot\File\u Createion.ps1”$servername