get the folder name of where the script is stored.


hi,

i have test file (am new powershell);

$mydir = $psscriptroot  write-host "executing following directory: $mydir"

which me outputs;

c:\users\user\downloads

what need output, top folder only, no full path, eg. downloads (where script physically located)

and not display c:\users\user\ portion

the closest got using -noqualifier option, omits c: part

is there direct way call this, or maybe through replace/manipulating text?

many thanks

$psscriptroot | split-path -leaf


[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Domain migration ERR3:7075 Failed to change domain affiliation, hr=8007054a This operation is only allowed for the Primary Domain Controller of the domain

How do a find data in one file, search for it in another file and if not found, write a custom message to another file