Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Invoking Cmdlet Get-Location from cmdlet,cant get Currnt Directory

Reply
 
Old 06-05-2008   #1 (permalink)
Vikram


 
 

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:

>>>>
RunspaceInvoke invoker = new RunspaceInvoke();
foreach(PSObject result in invoker.Invoke("Get-location"))
{
Console.WriteLine(result.Members["Path"].Value);
}
Quote:
Quote:
Quote:

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





My System SpecsSystem Spec
Old 06-05-2008   #2 (permalink)
Jeff


 
 

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
Vikram,

Try SessionState.Path.CurrentFileSystemLocation.Path.

Jeff
My System SpecsSystem Spec
Old 06-05-2008   #3 (permalink)
Vikram


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46