# how to set location path for the script

**URL:** <https://forums.powershell.org/t/how-to-set-location-path-for-the-script/5646>\
**Category:** PowerShell Help\
**Created:** [January 28, 2016, 5:59pm UTC](https://forums.powershell.org/t/how-to-set-location-path-for-the-script/5646 "2016-01-28T17:59:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankit-parmar](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@ankit-parmar](https://forums.powershell.org/u/ankit-parmar)\
**Post date:** [January 28, 2016, 5:59pm UTC](https://forums.powershell.org/t/how-to-set-location-path-for-the-script/5646/1 "2016-01-28T17:59:10Z")

</div>

Hi,

I have a script in which i have to set the location path for the software from where it will executed. Currently what i am doing is something like this -

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition  
Set-Location C:\Users\ankitpar\Downloads\nuget.exe Install WindowsAzure.storage -Version 1.7.0.0

I don’t want to give the whole hardcore path. Just want to define in powershell language so kindly suggest. Any Insights would be appreciated.

Thanks  
Ankit

---

<div class="post-metadata">

**Author:** ![graham-beer1](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@graham-beer1](https://forums.powershell.org/u/graham-beer1)\
**Post date:** [January 28, 2016, 7:14pm UTC](https://forums.powershell.org/t/how-to-set-location-path-for-the-script/5646/2 "2016-01-28T19:14:02Z")

</div>

Hi Ankit,

You could use $PSScriptroot if your using version 3 or above.

Here is a snippet from About\_Automatic\_Variables help topic:

$PSScriptRoot  
Contains the directory from which a script is being run.

```
   In Windows PowerShell 2.0, this variable is valid only in script modules
   (.psm1). Beginning in Windows PowerShell 3.0, it is valid in all scripts.

```

so if you run the script from root of C (Which you normally don’t, just an example) you could use it like this:

$PSScriptroot\Users\ankitpar\Downloads\nuget.exe

Does that help ?

---

<div class="post-metadata">

**Author:** ![ankit-parmar](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@ankit-parmar](https://forums.powershell.org/u/ankit-parmar)\
**Post date:** [January 28, 2016, 7:29pm UTC](https://forums.powershell.org/t/how-to-set-location-path-for-the-script/5646/3 "2016-01-28T19:29:36Z")

</div>

Thanks for the reply… I have done what you have suggest like given below -

$PSScriptroot\Users\ankitpar\Downloads\nuget.exe Install WindowsAzure.storage -Version 1.7.0.0

but getting error below so could you suggest me about this?

At line:1 char:14

- $PSScriptroot\Users\ankitpar\Downloads\nuget.exe Install 'WindowsAzure.storage - …
- 

```
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

```

Unexpected token ‘\Users\ankitpar\Downloads\nuget.exe’ in expression or statement.  
At line:1 char:14

- $PSScriptroot\Users\ankitpar\Downloads\nuget.exe Install 'WindowsAzure.storage - …

Thanks

---

<div class="post-metadata">

**Author:** ![graham-beer1](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@graham-beer1](https://forums.powershell.org/u/graham-beer1)\
**Post date:** [January 28, 2016, 8:22pm UTC](https://forums.powershell.org/t/how-to-set-location-path-for-the-script/5646/4 "2016-01-28T20:22:23Z")

</div>

If you run it as a one-liner it won’t work. Try wrapping it in a function a little function:

```
Function set-path {

#set the location path for the software install
$PSScriptroot\Users\ankitpar\Downloads\nuget.exe

}
```

This is the basic of the basic as i don’t have time to make it all singing all dancing. But should run to show you how it works.

---

<div class="post-metadata">

**Author:** ![ankit-parmar](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@ankit-parmar](https://forums.powershell.org/u/ankit-parmar)\
**Post date:** [January 28, 2016, 9:09pm UTC](https://forums.powershell.org/t/how-to-set-location-path-for-the-script/5646/5 "2016-01-28T21:09:35Z")

</div>

I have executed like below -

Function set-path {  
$PSScriptroot\Users\ankitpar\Downloads\nuget.exe Install WindowsAzure.storage -Version 1.7.0.0  
}

Still giving error -

At line:3 char:14

- $PSScriptroot\Users\ankitpar\Downloads\nuget.exe Install WindowsAzure.storage -V …
- 

```
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

```

Unexpected token ‘\Users\ankitpar\Downloads\nuget.exe’ in expression or statement.  
At line:3 char:14

- $PSScriptroot\Users\ankitpar\Downloads\nuget.exe Install WindowsAzure.storage -V

Thanks  
Ankit

---

<div class="post-metadata">

**Author:** ![graham-beer1](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@graham-beer1](https://forums.powershell.org/u/graham-beer1)\
**Post date:** [January 28, 2016, 10:31pm UTC](https://forums.powershell.org/t/how-to-set-location-path-for-the-script/5646/6 "2016-01-28T22:31:11Z")

</div>

This will set the folder :

```
Function Set-Folder {

#Set folder 
$Directory = resolve-path $PSScriptRoot\temp 

#Demonstrate result
$Directory

}#end of function
```

Not sure what you are doing with the nuget.exe. Is “Install WindowsAzure.storage -Version 1.7.0.0” part of the syntax to use with nuget.exe ?

---

<div class="post-metadata">

**Author:** ![ankit-parmar](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@ankit-parmar](https://forums.powershell.org/u/ankit-parmar)\
**Post date:** [January 29, 2016, 2:32am UTC](https://forums.powershell.org/t/how-to-set-location-path-for-the-script/5646/7 "2016-01-29T02:32:18Z")

</div>

hey,

thanks and sorry… i am newbie in powershell so not much knowledge … actually here i am trying to install package of azure though nuget.exe. nuget is the package for the microsoft development platform and as azure is microsoft product so i am trying to install azure through that.

Thanks & Regards  
Ankit

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:43pm UTC](https://forums.powershell.org/t/how-to-set-location-path-for-the-script/5646/8 "2024-05-16T20:43:02Z")

</div>


