Scripting Windows 7 Libraries

Recently I had to create a script to work with Libraries in Windows 7. Searching thru the Windows SDK, I found that this functionality was given in shell32.dll. I started to think p/invoke, but luckily someone had already created a .NET library to do this. So, using those .NET libraries made it all simpler.

This time I will try to manage the script through codeplex, and I have created a project and uploaded the script to http://windowslibrariespsh.codeplex.com

Release Notes

Short install guide:
(Extract to one of your folders given in $ENV:PSModulePath to simplify usage.)
Steps to install to your Modules folder:
Extract content from zip file to
~/documents/windowspowershell/modules/Windows7Library
If you don`t have the Modules folder in your WindowsPowershell folder, just create it.
From inside your Powershell session type the following command:
Import-Module Windows7Library


PLEASE NOTE
If this fails, please check that you allow scripts to run. If you demand Signed scripts, this script is not signed.
Also note that you might have to Unblock the file (as the file is downloaded from the Internet).
This should be done on the file Windows7Library.psm1 that you just extracted. (Right-Click the file, Properties and Unblock)
The commands inside the module is:
*Get-Library
*Add-Library
*Get-LibraryFolder
*Set-LibraryFolder
*Add-LibraryFolder
*Remove-LibraryFolder
*Get-KnownFolder

How to use?

Get-KnownFolder

To see all the knownfolders:
Get-KnownFolder -list
To get the path to the Documents Library
(Get-KnownFolder "DocumentsLibrary").Path

Get-Library

To read the Documents Library object:
$library=Get-Library (Get-KnownFolder "DocumentsLibrary").Path
Your could now play with the Library object:
$library | get-member

Get-LibraryFolder

Returns a list of the defined library folders
Get-LibraryFolder (Get-KnownFolder "DocumentsLibrary").Path

Add-LibraryFolder

Adds an path to the library
Add-LibraryFolder -LibraryPath(Get-KnownFolder "DocumentsLibrary").Path "\\server\share\folder"

Remove-LibraryFolder

Removes an defined library folder
Remove-LibraryFolder -LibraryPath (Get-KnownFolder "DocumentsLibrary").Path "\\server\share\folder"

Set-LibraryFolder

Set-LibraryFolder lets you define the default save folder for the library (note that the folder must be included in the library)
Set-LibraryFolder -LibraryPath (Get-KnownFolder "DocumentsLibrary").Path -DefaultSaveFolder "c:\docs"

Add-Library

With Add-Library you could create your own Libraries
Add-Library -Name "My Own Library" -Path "c:\users\user\Documents\"
(note that path here is where to store the library file (library-ms)

Have fun with this, and please, let me know of any improvments :)

Comments

# access windows 7 Libraries with Powershell said:

Pingback from  access windows 7 Libraries with Powershell

Thursday, November 25, 2010 2:25 AM
# access windows 7 Libraries with Powershell - Just just easy answers said:

Pingback from  access windows 7 Libraries with Powershell - Just just easy answers

Saturday, September 07, 2013 8:45 AM