简体   繁体   中英

POWERSHELL execute a file powershell script but from different path

I want to execute a powershell script file, it works but if I am in the same path that the script

....
$toto=(Get-ChildItem -Path "C:\Users\toto\Desktop\titi\tutu)

I work with the variable $toto

I execute the script from :

 PS C:\Users\toto\Desktop\titi> C:\Users\toto\Desktop\titi\script.ps1 = it works

but when I am below s subdir, not knowing the current "working directory" :

 C:\Users\toto\Desktop\ C:\Users\toto\Desktop\titi\script.ps1

how to resolve that please

我猜你需要这样的东西:

$toto=(Get-ChildItem -Path "$PSScriptRoot\tutu")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM