![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Invoking Cmdlet Get-Location from cmdlet,cant get Currnt Directory Hi If we do a Get-location on a powershell it displays the curent working directory. And i want the same current working Directory when i am invoking a custom made cmdlet from prompt( in the working directory). Ex: C:\TesT> New-CustomCmdlet In the above case in My custom cmdlet i want the directory name to be "C:\Test\" but Its gives C:\Documents and Settings\myname ( This is the directory, which is the root directory when powershell is launched). In the ProcessRecord the following code is written Quote: Quote: Quote: >>>> foreach(PSObject result in invoker.Invoke("Get-location")) { Console.WriteLine(result.Members["Path"].Value); } Quote: Quote: Quote: >>>>>. the processRecord to the following statement "RunspaceConfiguration config = RunspaceConfiguration.Create(); Runspace myRunSpace = RunspaceFactory.CreateRunspace(config); myRunSpace.Open(); Pipeline pipeLine = myRunSpace.CreatePipeline("Get-Location"); Collection<PSObject> results = pipeLine.Invoke(); foreach (PSObject result in results) { Console.WriteLine(result.Members["Path"].Value); } " Then also the result was same C:\Documents and Settings\myname. How to i get the current working Directory from where i launch the cmdlet? Or is there any bug in powershell related to this Any help will be greatly appreciated. Thanks |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Invoking Cmdlet Get-Location from cmdlet,cant get CurrntDirectory On Jun 5, 3:17 pm, Vikram <Vik...@xxxxxx> wrote: Quote: > Hi > If we do a Get-location on a powershell it displays the curent working > directory. And i want the same current working Directory when i am invoking a > custom made cmdlet from prompt( in the working directory). > > Ex: > C:\TesT> New-CustomCmdlet > > In the above case in My custom cmdlet i want the directory name to be > "C:\Test\" > but Its gives C:\Documents and Settings\myname ( This is the directory, > which is the root directory when powershell is launched). In the > ProcessRecord the following code is written > > RunspaceInvoke invoker = new RunspaceInvoke(); > foreach(PSObject result in invoker.Invoke("Get-location")) > { > Console.WriteLine(result.Members["Path"].Value); > }>>>>>. > > I tried using the above commands using Runspace configuration and changed > the processRecord to the following statement > > "RunspaceConfiguration config = RunspaceConfiguration.Create(); > Runspace myRunSpace = RunspaceFactory.CreateRunspace(config); > myRunSpace.Open(); > Pipeline pipeLine = myRunSpace.CreatePipeline("Get-Location"); > Collection<PSObject> results = pipeLine.Invoke(); > foreach (PSObject result in results) > { > Console.WriteLine(result.Members["Path"].Value); > } > " > > Then also the result was same C:\Documents and Settings\myname. > > How to i get the current working Directory from where i launch the cmdlet? > Or is there any bug in powershell related to this > > Any help will be greatly appreciated. > > Thanks Try SessionState.Path.CurrentFileSystemLocation.Path. Jeff |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Invoking Cmdlet Get-Location from cmdlet,cant get Currnt Direc Hi Jeff It works!!!! Thanks vikram "Jeff" wrote: Quote: > On Jun 5, 3:17 pm, Vikram <Vik...@xxxxxx> wrote: Quote: > > Hi > > If we do a Get-location on a powershell it displays the curent working > > directory. And i want the same current working Directory when i am invoking a > > custom made cmdlet from prompt( in the working directory). > > > > Ex: > > C:\TesT> New-CustomCmdlet > > > > In the above case in My custom cmdlet i want the directory name to be > > "C:\Test\" > > but Its gives C:\Documents and Settings\myname ( This is the directory, > > which is the root directory when powershell is launched). In the > > ProcessRecord the following code is written > > > > RunspaceInvoke invoker = new RunspaceInvoke(); > > foreach(PSObject result in invoker.Invoke("Get-location")) > > { > > Console.WriteLine(result.Members["Path"].Value); > > }>>>>>. > > > > I tried using the above commands using Runspace configuration and changed > > the processRecord to the following statement > > > > "RunspaceConfiguration config = RunspaceConfiguration.Create(); > > Runspace myRunSpace = RunspaceFactory.CreateRunspace(config); > > myRunSpace.Open(); > > Pipeline pipeLine = myRunSpace.CreatePipeline("Get-Location"); > > Collection<PSObject> results = pipeLine.Invoke(); > > foreach (PSObject result in results) > > { > > Console.WriteLine(result.Members["Path"].Value); > > } > > " > > > > Then also the result was same C:\Documents and Settings\myname. > > > > How to i get the current working Directory from where i launch the cmdlet? > > Or is there any bug in powershell related to this > > > > Any help will be greatly appreciated. > > > > Thanks > Vikram, > > Try SessionState.Path.CurrentFileSystemLocation.Path. > > Jeff > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Quest AD cmdlet -what is the cmdlet to remove computer object | PowerShell | |||
| [BLOG POST]: Invoking cmdlets within a cmdlet | PowerShell | |||
| Whether a cmdlet derives from cmdlet or pscmdlet | PowerShell | |||
| Invoking a cmdlet from another cmdlet | PowerShell | |||
| How to add to Group in Active Directory.... And has anyone a cmdlet? | PowerShell | |||