NerdyHearn
Home
Blog

Contact
Mailing List

Software

Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail

Sites
DocuTerminal
How Long For Me
My Music To Me
SaveMySerials
TypeCount

Blog
Twitter

NerdyHearn - Blog


<< Back To All Blogs

Current file path in custom PowerShell Cmdlet

Wednesday, April 1st, 2009

As obvious as this may seem it is not very easy to find out how to obtain the current location of the filesystem from within a custom PowerShell Cmdlet. This is very necessary when attempting to write files to the current directory that is executing the cmdlet, saving files to the currect directory, etc.

First, you will need to make sure that you are inheritting from PSCmdlet and not the generic Cmdlet. Discussion on this is out of the scope of this entry, but basically in order to access Console-specific information in a Cmdlet (such as profiles, environment information, paths, etc) you need to inherit from PSCmdlet.

You can then access the current path (this will be where your PowerShell console is currently sitting, so say if you changed to C:Test it would give you that path) by using the property SessionState.Path.CurrentFileSystemLocation.Path.

Pretty simple now that I'm aware of it, but took me a little time to dig up.

Hopefully that will help some of you out.

PowerShellin' Tom Out.

Tags

PowerShell

Related Blogs

Using Remote Powershell
Recursively removing SVN bindings with PowerShell
Programatically Retrieving an Assembly's PublicKeyToken through a PowerShell CmdLet
Determine Forest and Domain Functional Levels in Powershell
Uninstalling PowerShell V1.0 from Windows Server 2003

Comments

Currently no comments.

Add A Comment

Name:


URL:


Email Address: (not public, used to send notifications on further comments)


Comments:



Enter the text above, except for the 1st and last character:


NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. DocuTerminal - Online Filing Cabinet solution. Scan, search and archive your paper documents. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers My Music To Me - Stream your subsonic music collection to your Sonos wireless system TypeCount - Count how often you type across different computers! ServrTrackr - Monitor your SSL certificates, website uptime, and DNS configurations