Skip to content

A cmdlet is a lightweight Windows-PowerShell extension to make ours and yours work easier.

License

Notifications You must be signed in to change notification settings

mbc-engineering/cmdlet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PowerShell Cmdlets and Providers

Project for extensions like cmdlet or providers for Windows-Powershell.

Powershell Gallery Build Status Release Status

Requirements

  • .Net Framework >= 4.7.1
  • PowerShell >= 5.1

MongoDbGridFs Provider

This project is an extension for the Windows-Powershell and gives the easy possibility to work with a MongoDB-GridFs.

PSDrive in Action

How to use:

Install from Powershell Gallery (Install-Module -Name MongoDbGridFsProvider) or just run the setup to install and register the provider on your system. But if you want to try it first, without installation or as portable version, you can import the MongoDbGridFsProvider.psd1 with the Import-Module by your own.

Check the MongoDbGridFs Provider is correctly installed with

> Get-PSProvider
Name                 Capabilities                                                                                                       Drives
----                 ------------                                                                                                       ------
Registry             ShouldProcess, Transactions                                                                                        {HKLM, HKCU}
Alias                ShouldProcess                                                                                                      {Alias}
Environment          ShouldProcess                                                                                                      {Env}
FileSystem           Filter, ShouldProcess, Credentials                                                                                 {C, D, E, H...}
Function             ShouldProcess                                                                                                      {Function}
Variable             ShouldProcess                                                                                                      {Variable}
MongoDbGridFs        Filter, ExpandWildcards, ShouldProcess, Credentials                                                                {NspMongo}
Certificate          ShouldProcess                                                                                                      {Cert}
WSMan                Credentials                                                                                                        {WSMan}

Register PSDrive:

In order to use the provider, you must first register it.

> New-PSDrive -PSProvider MongoDbGridFs -Name Mongo -Root 'localhost' -Port '27017' -Database 'MyDb' -Collection 'fs.files' -Verify

Now the provider can simply be addressed by its name.

If credentials are required, set the parameter -Credential with a PSCredential value. The simplest way is to use a dialog with Get-Credential -Message "MongoDb login"

> New-PSDrive -PSProvider MongoDbGridFs -Name Mongo -Root 'localhost' -Port '27017' -Database 'MyDb' -Collection 'fs.files' -Verify -Credential (Get-Credential -Message "MongoDb login")

The parameters -Port and -Collection don't have to be set (default Port='27017' and Collection='fs').

Remove PSDrive:

For listing all existing drive use

> Get-PSDrive -PSProvider MongoDbGridFs
Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
Mongo                                  MongoDbGridFs localhost

and then removing it

> Remove-PSDrive Mongo

Get-ChildItem

Returns a list of all existing elements in the registred collection. This command gives a quick overview of existings elements and some meta-inforamtions.

Example:

> Get-ChildItem Mongo:

FileName     Id                       UploadDateTime      length
--------     --                       --------------      ------
testFile     5cd92feb5ba2196a6c5f0da2 13.05.2019 08:50:51      1

Get-Item

Get a specific item from the collection, given by die objectId.

Example:

> Get-Item Mongo:\5cd92feb5ba2196a6c5f0da2

In this way it is easy to store the binary content to a local drive

Example:

> Get-Item Mongo:\5cd92feb5ba2196a6c5f0da2 -Target c:\temp\content.txt

Set-Item

Upload an existing file to the collection.

Example for upload foo.txt to the collection:

> Set-Item Mongo:\foo.txt

Remove-Item

Deletes an existing element completely from the collection.

Example:

> Remove-Item Mongo:\123769231768231876

Rename-Item

Overwrites the file-name property in the collection of the given element.

Example:

> Rename-Item Mongo:\93097432780089734 -NewName foo2.txt

Get-Content

Get the content of an existing element from the collection.

Example:

> Get-Content Mongo:\93097432780089734

Set-Content

Create a new element in the collection with content of the Value parameter.

Example:

> Set-Content Mongo: -Name foo3.txt -Value "Test content"

Legal and Licensing

MongoDbGridFsProvider is under the Apache License 2.0.

About

A cmdlet is a lightweight Windows-PowerShell extension to make ours and yours work easier.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •