Powershell3.0及以后版本。
如果你的腳本需要添加額外資源,比如文本中的服務(wù)器名、圖片名等等,這時你需要考慮腳本的靈活性。
不要使用絕對路徑去指派你的資源路徑,在Powershell3.0中可以使用$PSScriptRoot替代你的腳本路徑(不支持2.0)
代碼如下:
$picture = "$PSScriptRoot/Resources/picture.png"
Test-Path -Path $picture
$data = "$PSScriptRoot/Resources/somedata.txt"
Get-Content -Path $data
$PSScriptRoot總是可以獲得你腳本運(yùn)行所在目錄名,當(dāng)然你可能會發(fā)現(xiàn)它在執(zhí)行時為空,這時你只需要將它保存到腳本中執(zhí)行即可。
|
新聞熱點(diǎn)
疑難解答
圖片精選