Is there a way in Powershell to provide virtual file systems in other file systems?

1.3k Views Asked by At

I know you can write support for custom PSDrives. But those are always a root of a file system. What would be nice if there was a way to allow for VFS start at arbitrary nodes of the file system, such as using Set-Location to enter archive file maybe and use them as if they were folders. (Kinda like Far does this).

Is there any way to achieve this? I know, it would be some work to get it right and working, but at the moment I am more interested whether it would be possible at all.

ETA: What I don't want is a new PSDrive for every archive I enter, so the following isn't actually what I'm after:

PS C:\Path> Invoke-Magic stuff.zip
PS C:\Path> Set-Location MyNewDrive:
PS MyNewDrive:> _

but rather

PS C:\Path> Set-Location stuff.zip
PS C:\Path\stuff.zip> _
3

There are 3 best solutions below

0
dahlbyk On BEST ANSWER

What you're describing is a FileSystem provider that also considers archives to be container objects. As FileSystemProvider is sealed, I think you would have to write your own NavigationCmdletProvider that does your magic.

3
Richard Berg On

Sure. In fact, you can already do this to some degree without writing any snap-in code. For example:

New-PsDrive -Scope Global -Name MyMod -PSProvider FileSystem -Root (split-path $profile | join-path -child Modules)
dir MyMod:\
1
Shay Erlichmen On

You need to write a provider, here is an example for a provider for SourceSafe (old but still relevant)