A PowerShell DNS Suffix Tool

The other day my good friend Greg Shields asked for a little assistance with a PowerShell problem. He was trying to use PowerShell to set the primary DNS suffix for a computer. This  is different than the DNS suffix you can set on a network adapter configuration. Instead, he was looking at the dialog box you get when you set the computer name under advanced properties from the control panel System settings.

system1

We couldn’t find any cmdlet that would modify this setting. Eventually Greg discovered that you need to set both the Domain and NV Domain settings under

HKLM:\system\CurrentControlSet\Services\tcpip\parameters. Now that, was something I could work with.

Within short order I had a simple module, DNSSuffix, with commands to get the domain settings and set them.  The functions use PowerShell remoting so that you can manage remote computers. You can check out the documentation and code in Github (https://github.com/jdhitsolutions/DNSSuffix) or install the module from the PowerShell Gallery: Install-Module DNSSuffix.

 

If you run into issues or have suggestions, please use the Issues section of the GitHub repository.

Sending Files to Your Browser with PowerShell

Over the course of the last year I’ve been using markdown files much more, especially as part of the Platyps module. Even though I have a markdown editor and I can also preview files in VS Code, sometimes I want to see the file in my browser which has a markdown viewer plugin. Or I might want to see something else in my browser. I had been pasting the file path and pasting it into the browser, but of course realized I should get smart about this and write a PowerShell function to make this easier. Thus was born Out-Browser. Although it proved a bit trickier than I expected because the registry was involved.

Continue reading

Export Registry Printer Information I came…

Export Registry Printer Information

I came across this post http://www.oncallpros.com/2011/11/02/powershell-export-your-print-configuration-from-registry/ on exporting printer information from the registry in PowerShell. I wanted to offer some constructive suggestions but could find no way to comment so I'll do so here.

First, the article introduces some good PowerShell concepts. I like that he is using Test-Path. Although I'd suggest using Join-Path instead of concatenation. I also like the use of Write-Host to display progress. An even better approach for a future version might be to use Write-Progress. I'm going to see about using that more myself as I think it is a cmdlet that doesn't get the attention it deserves.

But my main concern with the script is that it feels too much like VBScript and parsing text. He's not really taking advantage of the PowerShell pipeline. The core command can be this one line command.

get-childitem HKLM:SYSTEMCurrentControlSetControlPrint -Recurse |
get-itemproperty |
select @{Name="RegKey";Expression={Convert-Path$_.pspath}},* -exclude PSParentPath,PSChildname,PSProvider,PSPath

I wasn't looking for a one line command, it just turned out that way.

Personally, this is the code that I would put in the script because it writes objects to the pipeline. Now I have options. If I want a formatted text list I can do it:

PS C:> c:sciriptsget-printerregistry.ps1 | format-list | out-file printers.txt

Or perhaps today I need it as an xml file I wan reimport later.

PS C:> c:sciriptsget-printerregistry.ps1 | export-clixml printers.xml

The point is to offer flexibility and think objects in the pipeline.

On a more personal (pet peeve) note, if you are going to post code samples more than a few lines long, please, please offer a text file download. Copying and pasting code from websites is ugly and time consuming.

So, look at the original post and look at my suggestions. What do you think?

Powershell – Export your print configuration from registry | On-Call Pros, LLC

I was asked to produce this script for follow up checking of driver versions later on or possible settings which can cause problems.   The idea would be that a master file is updated on a website and …

Get Registry Size and Age

I’m not sure why the registry has been on my mind lately. I probably need a vacation to get out more. But I put together a relatively simple Windows PowerShell function to retrieve registry statistics that you might find useful. My Get-Registry function will return information about the size of a registry as well as its age. Continue reading

Join Me in Atlanta for TechEd 2011

I’m very excited to be presenting at Microsoft TechEd North America 2011, this year in Atlanta, GA. I’ll be presenting two breakout sessions and will likely be there most of the week so there will be plenty of time to connect with people. I have what I hope are some very interesting sessions. Continue reading