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
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 ?
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
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
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.
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
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
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 ?
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