Skip to main content

Posts

Showing posts with the label MOC 10325

How to pipe data to cmdlets who’s parameters do not accept input via the PowerShell pipeline.

The PowerShell pipeline is one of the key features of PowerShell that allows you to greatly reduce the script code that you need to write to accomplish your goals.  Unfortunately, not all parameters in a cmdlet allow you to feed them data via the PowerShell pipeline. Here is an example. The Active Directory module has a cmdlet called Add-ADGroupMember.  This cmdlets intended purpose is to add an object, such as a user, to a group in active directory.  The Members parameter is used to add an object to the group.  Here is the help file for this parameter: PS C:\> get-help Add-ADGroupMember -Parameter Members -Members <ADPrincipal[]>     Specifies a set of user, group, and computer objects in a comma-separated     list to add to a group. To identify each object, use one of the following     property values. Note: The identifier in parentheses is the LDAP display     name.   ...

Adding a Comment to a GPO with PowerShell

As I'm writing this article, I'm also writing a customization for a PowerShell course I'm teaching next week in Phoenix.  This customization deals with Group Policy and PowerShell.  For those of you who attend my classes may already know this, but I sit their and try to ask the questions to myself that others may ask as I present the material.  I finished up my customization a few hours ago and then I realized that I did not add in how to put a comment on a GPO.  This is a feature that many Group Policy Administrators may not be aware of. This past summer I attended a presentation at TechEd on Group Policy.  One organization in the crowd had over 5,000 Group Policies.  In an environment like that, the comment section can be priceless.  I always like to write in the comment section why I created the policy so I know its purpose next week after I've completed 50 other tasks and can't remember what I did 5 minutes ago. In the Group Policy module for Pow...

Backup event logs on multiple servers with PowerShell

This PowerShell cmdlet was developed for my PowerShell class in Miami.  This is very specific to their needs.  The requirement was to be able to backup event logs from multiple servers to a single location.  The logs needed to be saved in a folder structure of Year/Month.  They also needed an option to clear the log.  This was a fun one, but complex so I took it on. It is designed as a function so you can add it to a custom library. Function Backup-EventLog { [ CmdletBinding (HelpUri = 'http://get-help-jason-yoder.blogspot.com/2012/10/backup-eventlog.html' ) ] Param (     [ Parameter (Mandatory = $True ) ][ String []] $ComputerName ,     [ Parameter (Mandatory = $True ) ] $LogFiles ,     [ Parameter (Mandatory = $True ) ][ String ] $Path ,     [ Switch ] $ClearLog ,     [ Switch ] $Quiet )     # Support Function: Write-Info ---------------------...