Skip to main content

Posts

Showing posts from April, 2013

PowerShell Scripting Games 2013 - Advanced Event 1 - My Submission and Learnings

Please review my submitted code and vote on what you think, also please leave a comment.

http://scriptinggames.org/entrylist.php?entryid=170

While the below script isn't exactly what I submitted, it is close, and what I would have ended up with if I had been a bit more patient and didn't feel the need to submit before it was too late. But I digress...

I want to explain why I think this script in general is good, if not an excellent example of how to accomplish the events goals.

The event goals are summarized as having to take files from source X, Y, Z and move to A if the file age is greater than # days old.

Honestly, the requirements left a lot of ambiguity, that I believe, having voted on several entries, produced a variety of styles. The script I ended up with below is based on my original submission and the adaptions I made based on what I learned from others examples, but in the most simplified manner I could envision with PowerShell 3.0 and that fit well within the framew…

PowerShell 4.0 Wishlist - Select-Object Enhancement

I mostly like the way Select-Object allows you to create custom objects and properties. However, I really wish it was simpler to create properties with ScriptBlock values without the lengthy Hashtable definition.

If only Select-Object would implement something like this so you can define a property ScriptBlock without the long Hashtable definition. Similar to how this custom function I wrote allows you to define a property name as the Key of the Hashtable and the value as the ScriptBlock or name of the property.

Wishlists are usually wishful thinking, there are probably reasons why Select-Object behaves like it does, it isn't that bad since you can short-hand the keys but it just doesn't seem as fluid. Here is to wishing for a better Select-Object.
function ConvertTo-PSCustomObject {      [CmdletBinding()]  param(          [ValidateNotNullOrEmpty()]          [Parameter(Mandatory = $true, Position = 0)]          [Array] $Property,          [Parameter(Mandatory = $true, ValueFrom…

PowerShell Scripting Games 2013 - Advanced Practice Solution

This is my solution to the advanced practice event for the PowerShell scripting games. The beauty of this script compared to some of the other entries I saw posted, is that it totally relies upon the built-in capabilities of PowerShell 3.0 for the majority of the required features.
The Solution <#.SYNOPSIS      Get-ComputerUpTime displays the current up time (hours, minutes, seconds) of the specified computers.  .DESCRIPTION      Connects to the computer with CIM to retrieve the Win32_OperatingSystem LastBootUpTime property and returns       the computer name and the up time duration represented as total number of hours, minutes, and seconds.  .PARAMETER ComputerName      The list of computers to retrieve the uptime from.  .INPUTS      An array of strings or an array of objects that contain a property ComputerName.  .OUTPUTS      PSCustomObject. Get-ComputerUpTime will return the computer name, total hours, minutes, and seconds since the computer operating system was loaded.  .EXAMP…

FIM 2010 R2 Self-Service Password Reset Auto-Registration

I have been working on our FIM 2010 R2 SP1 lab environment looking for ways to simplify some of the overly complicated scenarios we had to implement to workaround the limitations in FIM 2010. One of those workarounds was the auto-registration of SSPR for new employees. When we onboard a new employee, we want to create a simple SSPR for them to get their first-time password reset.

Prior to the R2 release we were using the http://fim2010client.codeplex.com/ client and PowerShell to complete the registration process on a daily schedule. I was working on converting this to use the R2 registration cmdlets and combined it with PowerShell 3.0 Workflows to get to a solution similar to this.
[CmdletBinding()]  param()  begin {      workflow Invoke-RegisterSSPR {          InlineScript {              Import-Module FIM          }  $workflow = InlineScript { Get-FIMResource -Filter '/WorkflowDefinition[DisplayName = "Password Reset AuthN Workflow for New Employees"]' }  $members  …

FIM 2010 R2 SSPR PowerShell Registration MPRs

If you are setting up your FIM 2010 R2 environment to support the registration commands in the FIMAutomation snapin, then this will help you quickly do that if you have the FIM module from http://fim.codeplex.com installed.
[CmdletBinding()]  param(      [string] $ComputerName = $ENV:COMPUTERNAME  )  begin {      Import-Module FIM  $Administrators       = Get-FIMResource -Filter '/Set[DisplayName = "Administrators"]'         -ComputerName $ComputerName$AllPeople            = Get-FIMResource -Filter '/Set[DisplayName = "All People"]'             -ComputerName $ComputerName$AllGateRegistrations = Get-FIMResource -Filter '/Set[DisplayName = "All Gate Registrations"]' -ComputerName $ComputerName}  end {      New-FIMResource -ComputerName $ComputerName -ObjectType ManagementPolicyRule -Set @{           ActionParameter          = @('*');          ActionType               = @('Create', 'Delete');          Disable   …