Skip to main content


Showing posts from March, 2015

Embedding Expressions in Select-Objects

I had my first taste of using Select-Objects in a way more than just modifying values on output or to specifically pick a set of attributes to list. When someone asks for a list of users and their managers, meh, no big deal. When they ask for the user, their manager, and their manager’s email address -- well, no big deal but not as much of a no big deal as the first one. I found it a bit annoying that I had to write a script to do this every time I wanted to get this type of information so I did a bit of exploring. Turned out a little while ago, while experimenting in optimizing speed in a script, I had tried a method of using Select-Object to create a custom object .   Using Select-Object to Pull Manager Detail on the Fly $myData | select @{n= 'UserId' ;e={$_.samaccountname}}, @{n= 'Created' ;e={$_.lastlogon}}, @{n= 'Name' ;e={$}}, @{n= 'Manager' ;e={$_.manager}}, @{n= 'Manager Email' ;e={ (get-aduser $_.m

DHCP Scope Information

Thought I’d squeeze in this post before Windows Server 2003 drifts off into the sunset. (Don’t pretend like you don’t have these servers floating around.) Okay, so, I was recently asked to validate that some DHCP scope work was performed correctly. Validation in this case was to pull all the scope options. It would have been immensely helpful to use PowerShell to do this. However, I made do without it using Netsh .   Retrieving Scope Options for a Single Scope netsh dhcp server <servername> scope <scopeaddr> show optionvalue That’s easy. How about for every scope on my server? That’s easy, too, as it turns out.   Retrieving Scope Options for All Scopes for /f %a in ( 'netsh dhcp server <servername> show scope ^| find /i "."' ) do @netsh dhcp server <servername> scope %a show optionvalue

PowerShell: Updating Terminal Services Profile Information

If you’ve done any dabbling in the AD cmdlets and attempted to update terminal services information, you’ll hit a wall with the traditional cmdlets. Why? Well, simply, what you see in AD Users and Computers is not the way the values are actually stored , as Ed explains. Well, luckily, it turns out it’s not that hard. I was asked to come up with a process to update the profile path. This is a sample of what I ended up with: $PathValue = <myUserPath> $myUser = "myUserName" $User = [ADSI] LDAP://$((Get-AdUser $myUser).distinguishedname) $User.psbase.invokeset( "TerminalServicesProfilePath" ,$PathValue) $User.setinfo()   Back to the Scripting Guys’ script, here is a function that shows the possible values that can be modified: function SetTSProperties() { $ou = [adsi] "LDAP://ou=mytestou,dc=nwtraders,dc=com" $user = $ou.psbase.get_children().find($userDN) $user.psbase.invokeSet( "allowLogon" ,1) $user.psbase.invokeSet( "Terminal