header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left
Random Cmdlets
Add-PublicFolderAdministrativePermission
Use the Add-PublicFolderAdministrativePermission cmdlet to add administrative permissions to a public folder or a public folder hierarchy.


Update-SafeList
Use the Update-SafeList cmdlet to update the safelist aggregation data in the Active Directory directory service. Safelist aggregation data is used in anti-spam filtering in Microsoft Exchange Server 2007. EdgeSync replicates safelist aggregation data to computers that have the Edge Transport server role installed.


Export-Message
Use the Export-Message cmdlet to copy a message from a queue on a computer that has the Hub Transport server role or the Edge Transport server role installed to a specified file path in a Microsoft Exchange Server 2007 organization.


Pop-Location
Changes the current location to the location most recently pushed onto the stack. You can pop the location from the default stack or from a stack that you create by using Push-Location.


Set-Mailbox
Use the Set-Mailbox cmdlet to modify the settings of an existing mailbox. You can use this cmdlet for one mailbox at a time. To perform bulk management, you can pipeline the output of various Get cmdlets (for example, the Get-Mailbox or Get-User cmdlets) and configure several mailboxes in a single-line command. You can also use the Set-Mailbox cmdlet in scripts.


Get-ReceiveConnector
Use the Get-ReceiveConnector cmdlet to view the configuration information for a Receive connector on a computer that has the Hub Transport server role or the Edge Transport server role installed.


Out-Printer
Sends output to a printer.


Move-ItemProperty
Moves a property from one location to another.


Get-Trap
The Get-Trap cmdlet provides a listening point for SNMP traps.


Set-AdSiteLink
Use the Set-AdSiteLink cmdlet to assign an Exchange-specific cost to an Active Directory IP site link.


  
Latest Scripts from PoshCode.org

egg_timer
A script I submitted for Event 10 of the Scripting games. Displays a simple Windows Form that counts down three minutes. It makes a good example for using Windows forms.

SnapReminder
Remind the users of their snapshots - for use in VMware, see this post for more details: http://www.virtu-al.net/2009/06/22/powercli-snapreminder/

LibrarySqlBackup
Standalone script adapted from SQL Server Powershell Extensions (sqlpsx) http://sqlpsx.codeplex.com. Defines SQL Server backup and restore functions.

Format-TablePlus
This is a wrapper function for Format-Table that adds a @-Width@ parameter, and a @-PadEnd@ parameter (without which it trims the end of every line of output. Set -PadEnd to get the original Format-Table behavior of adding needless whitespace on the end of every line of output.

Colorize Subversion SVN
Colorize STAT, UPDATE and DIFF (without params) commands output for Subversion (svn) and Mercurial (hg). Here's a PowerShell functions that you can use to make those numerous commands you run every day via the PowerShell CLI a little easier to read by adding colors. Autodetect for svn or hg. Update autodetect to work with psdrives that are a UNC path. Also now works with repositorys in the root directory of drive. Added $args to each function so you can do things like sd -r2 -rtip -U0

Get-DirSize
A v2.0 function to recursively get the sizes of all subdirectories under a root path.

vProfiles
vProfiles V1.1 By Alan Renouf http://virtu-al.net, copies vSwitches and PortGroups from one host to another.

Prevent-Screensaver
Simulate user activity to prevent desktop lock or screensaver for specified period of time

TabExpansion for V2CTP3
The most needless, useless and worthless Tabexpansion for powershell.exe(v2.0CTP3) in PoshCode. Update: # Parameter name (and command alias) expansion with Ctrl+E ls -f *.txt -r | ? { $_.LastWriteTime -lt "2009/5" } | Select-String powershell -e OEM<Ctrl+E><tab>. <br> Get-ChildItem -Filter *.txt -Recurse | Where-Object { $_.LastWriteTime -lt "2009/5" } | Select-String powershell -Exclude OEM<tab> Get-ChildItem -Filter *.txt -Recurse | Where-Object { $_.LastWriteTime -lt "2009/5" } | Select-String powershell -Encoding OEM<tab> Get-ChildItem -Filter *.txt -Recurse | Where-Object { $_.LastWriteTime -lt "2009/5" } | Select-String powershell -ErrorAction OEM<tab><tab>...

TabExpansion
The most needless, useless and worthless Tabexpansion for powershell.exe(v1.0) in PoshCode. Please dot souce this script file to use. Update:. # WMI Namespaces expansion for Get-WmiObject gwmi -Namespace <tab>. Get-WmiObject -Namespace root\asp<tab>. # WMI Classes expansion which is corresponding to WMI Namespace (*) gwmi -Namespace ROOT\CIMV2\ms_409 -Class <tab>_<tab>. (*) it needs to remove old $PSHOME\WMIClasses.txt if it exists.
  
 

April 24th, 2009.

Idera, one of our sponsors has joined forces with Don Jones to create some super PowerShell videos that you can find HERE.  Best of all...  They are FREE!

Follow the link above for more information.  Don Jones covers the basics of PowerShell, using PowerShell and Active Directory, using PowerShell and Exchange 2007, using PowerShell and SQL Server 2008, and using PowerShell to manage servers and clients.

The Community has just taken a great leap in getting the word out about how cool PowerShell is!

Marco Shaw - Co-Community Director

Community News
New sponsor: Compellent

PowerShellCommunity.org has an exciting new sponsor: Compellent.  Just added to our sponsors page:

Compellent is a leading provider of enterprise-class network storage solutions...

Microsoft TechDays Defy All Challenges

On April 1st, 2009, Microsoft is putting on a free 24 hour virtual event covering developer-related topics.

There will be 95 live sessions provided via Live Meeting in the following tracks:
*Windows Development and Frameworks
*Windows Mobile Development
*Office...

Microsoft releases IIS7 PowerShell snapin

The full details are HERE.  Microsoft has just released a production version of a IIS snapin for managing IIS7 on Windows Server 2008.  This snapin is independent of any features shipping with Windows Server 2008 R2 (like PowerShell...

New Sharepoint and SQL forums

Due to recent interest in the forum, we've added two new discussion areas:

PowerShell Expert Panel at TechEd EMEA 2008

 We are extremely proud of the the job that Jonathan Medd (of the Get-Scripting Podcast) did at TechEd EMEA 2008 with a panel discussion which was made possible by support from PowerShellCommunity.org. You can find the video on

  
Recent Blog Entries
Jun 7

Written by: Karl Prosser
6/7/2008 12:32 AM

One thing that has bothered me about true cmdlets in contrast scripts is that they lived in SnapIns and couldn't be deployed with xcopy as scripts can because SnapIns required Registration/Installation. I build my own way to deal with this need some time ago, and thought that I'd start a blog series covering it. I call them Snapininis or SnapIn-Lites. A good thing is you can achieve the same end result in PowerShell V2 with modules - but that is V2 and a while away from being released, and then even further away from being fully deployed.

 

So how does this work?

1) you have to load an assembly into memory in powershell that contains your snapin.
2) you add the cmdlets directly into the runspace that is running and tell powershell to update its list of cmdlets.

Here is the C# code for a sample barebones SnapInini.

using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
 
namespace Snapinini
{
public class DynamicCmdLet
{
public static void Load()
{
CmdletConfigurationEntry conf = new CmdletConfigurationEntry("dummy-cmdlet", typeof(ForeachDictionaryCmdLet), null);
Runspace.DefaultRunspace.RunspaceConfiguration.Cmdlets.Append(conf);
Runspace.DefaultRunspace.RunspaceConfiguration.Cmdlets.Update();
Runspace.DefaultRunspace.CreateNestedPipeline(
"new-alias dcmd dummy-cmdlet; write-host 'snapinini loaded'",
false).Invoke();
}
}
[Cmdlet("dummy", "cmdlet")]
public class ForeachDictionaryCmdLet : System.Management.Automation.PSCmdlet
{
protected override void EndProcessing()
{
WriteObject("hello from the dummy cmdlet");
}
}
}

In the above sample I have a very very simple cmdlet. You can see that i get the defaultrunspace, go into its RunspaceConfiguration and add the cmdlets and update the list. I am additionally running some powershell script that adds an alias to the cmdlet and writes a message to the screen just as an example showing you that you can do more stuff if you wish. In the above code the load is a static method so its easy to call from powershell once you've loaded the assembly, but in all honesty the Load() code could just as well have been written in the calling PowerShell.

So how do we load and use this in PowerShell?

[system.Reflection.Assembly]::LoadFrom("snapinini.dll")
[snapinini.DynamicCmdLet]::load()
dummy-cmdlet
dcmd

 

Where to from here? This example is very simple, you could easily add multiple cmdlets into the equation, specify help files, add custom type definitions etc. Another thing I had experimented with is taking a real snapin and using reflection to see the cmdlets in it and adding them directly, however unless you know exactly what a snapin does this is dangerous because in its registration it might set up a bunch of other things also that are important.

Another thing I should cover next time is a safe way to load assemblies from any location and ensure that all their references get resolved seamlessly.

-Karl

Tags:

Your name:
Title:
Comment:
Add Comment    Cancel  
  

PowerShellCommunity is sponsoring this year's Microsoft Technet Scripting Games, along with the new PoshCode.org. Submit your entry today!

right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer