PowerShell Team
Automating the world one-liner at a time…
Latest posts
Configuring PowerShell for Remoting – Part 2 (Fan-In)
The features discussed in this blog post depend on PowerShell CTP3 release. Details about PowerShell CTP3 can be found at http://blogs.msdn.com/powershell/archive/2008/12/23/early-christmas-present-from-powershell-team-community-technology-preview-3-ctp3-of-windows-powershell-v2.aspx The Part 1 of this series concentrated on configuring PowerShell remoting through WinRM service. In this blog post, I will talk about configuring PowerShell through IIS, which we call as Fan-In. The WinRM service based PowerShell remoting is targeted for those users who want to administer/manage a machine(s) (or an asset on the mach...
Introducing the WMI Blog
The people over on WMI, WinRM, and BITS have started up a blog to share their systems management expertise with the world. Check it out: http://blogs.msdn.com/wmi/ Here are some fun posts to get you started: Accessing WMI Data via WinRM Let’s Troubleshoot WMI (Part 1: Remoting & Security) (this one includes a handy chart I wrote years ago to figure out what I needed to change when WMI couldn’t connect) Introducing BITS PowerShell Cmdlets Hope this Helps, James Brundage [MSFT]
Checking for bound parameters
I recently read an email where someone was asking how they could check in their function if a value had been provided to one of the parameters. Consider for example, The usual way I’ve seen people deal this problem is by providing a default value which gets assigned to $x in the case that a value wasn’t provided by the caller and then checking for that value. That works in the majority of cases, but let’s say that you wanted to differentiate between a default $null value and $null being passed by the caller. What would you do? If you’re on v2, a simple solution is ...
Setting Network Location to Private
The Network Location feature was introduced in Windows Vista. It provides an easy way to customize your firewall settings based on whether you trust or don’t trust the computers around you. There are three Network Location types - Private, Public and Domain. If your computer is a member of the domain then you won’t be able to change the Network Location type. If your computer is standalone or part of the workgroup, then you can choose what type of network location do you want - Public or Private. Private means that you are a member of the trusted network and you can lower your network security a little bit. Publi...
Many² ways you can set a variable value
There are many ways to set a variable's value. I just learnt one more yesterday. If you have others, please add comments # Simple# $ gets the variable, and = will assign it$a = 1 # With Variable Scope# The prepend is the scope, and could be global, script, and others# Useful when you want to keep things in script scope, or share them out in global scope$global:a = 1 # Complex variable names# Useful if you have a variable with the name ${Yahoo!Id}${a} = 1 # Using the Set-Variable cmdlet# Useful if you want to indirectly set the value# Has extra parameters like scopeSet-Variable a 1 # Using the variable provider# N...
Image Manipulation in PowerShell
The other week, I showed a Get-ProgID function that I used to help someone at Microsoft Research find a good object to talk to images. A few comments jumped to one of the possible solutions, which is to use the .NET Drawing assembly (which I have to load first). I wanted to be reasonably sure that the way to get at the image metadata was efficient and didn’t require loading up any assemblies PowerShell hadn’t loaded already. Looking at the output of Get-ProgID, Two COM objects jumped out at me: These two COM objects are part of a whole fun family of scriptable COM objects that work with the M...
Active Directory Administrative Center for Windows Server 2008 R2 implemented using ADPowershell!
Windows Server 2008 R2 doesn’t just add ADPowershell – it also adds Active Directory Administrative Center (or ADAC), a new GUI tool for AD administrators. Read about it on TechNet. What’s more, while you can’t tell just from looking at it, ADAC is implemented entirely over Windows PowerShell 2.0 and ADPowershell! Every read and write to AD goes through ADPowerShell. So, if you were wondering whether Windows PowerShell and ADPowershell are just for scripters -- they aren’t! Windows PowerShell and ADPowerShell provide a powerful and flexible management API for the construction of mana...
Get closure with GetNewClosure
Have you ever created scriptblocks on the fly, say in a foreach loop, and they totally mess up because they all have the same value? This is something sort of advanced, and typically used when you’re proxying an object. The most basic example would be, taken from (http://www.powershellcommunity.org/Forums/tabid/54/aff/1/aft/2506/afv/topic/Default.aspx) function add([int]$x) { return { param([int]$y) return $y + $x } }$m2 = add 2$m5 = add 5&$m2 3 #expected: 5 actual: 3&$m5 6 #expected: 11 actual: 6 The value for $x is $null for both. Why is that? Its because $x is $null in the local scope, the script...
Tied Variables in PowerShell
With Add-Type and $executioncontext you can add special varibles that have tied values. I made $random, and $now add-type @"using System;using System.Management.Automation;public class RandomVariable : PSVariable{Random r;public RandomVariable () : base("Random", 0, ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope) {r = new Random();} public override object Value { get {  ...