I am using a PowerShell file. I have a file inside the same folder, path can change but folder remains same.
How to use relative path, so there is no change in script?
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
}
instead of
Invoke-Expression -Command "d:\sysdba\File_Creation.ps1 $servername"
I want to use like .\file_creation.ps1
but it's not working.