Tag Archive: Powershell

May 30

Powershell Code: Discover a Local Global Catalog for Forest Queries

Sometimes it is necessary to query a Global Catalog (port 3268) for forest-wide data (such as checking for a ServicePrincipalName). Finding a local online GC is the best method for this. The script method prefers 2008 DCs. Here’s the code: 12345678910111213141516171819202122232425Import-Module ActiveDirectory IF ($TargetGC)     { ## OPEN IF TargetGC has a value   …

Continue reading »

May 23

Powershell Code: Discover local DC running ADWS

Often it is necessary to use the same DC to perform updates or errors will occur. Here’s a way to do this which provides connection testing (is the DC online) that you don’t get with Get-ADDomainController. This method finds a local DC running ADWS (Active Directory Powershell Web Service that runs on a DC) first, …

Continue reading »

May 16

Powershell Code: Fix Journal Wrap

One of my customers has an issue with DCs in far flung locations impacted by older hardware and power instability. For this (and other reasons) there are many, many Journal Wrap issues. Here’s a script that will fix a local DC’s Journal Wrap issue by performing a D2 (nonauthoritative restore). 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113Param (   [switch] $Fix …

Continue reading »

May 09

Powershell Code: Update the Registry on a Remote Computer

Sometimes you have to script something instead of using a GPO. In these instances, it can be helpful to update the registry on a remote computer. The easy way is using Powershell (New-ItemProperty or Set-ItemProperty) on a local box with Powershell 2.0. Modifying the registry on a remote computer is a little more complicated. Here …

Continue reading »

May 02

Powershell Code: Using Powershell to Hash files

I had a requirement to replace a config file on every workstation and not touch the file if it already exists. I thought about several ways to do this and ultimately ended up deciding to hash my “template” file and hash the existing file, only updating files that didn’t match. The code below is flexible …

Continue reading »

Apr 15

Powershell Code: Base64 Encode/Unencode (Decode)

Often I have requirements to change a password somewhere using a Powershell script and am required to enter it at run time. At this point, one has an option: include the password in a log file or not. I figured it would be good to have it in the log file (the script is run …

Continue reading »

Apr 02

Powershell and UNC Paths

One of the fun things about working with “programming” (I use the term loosely when it comes to scripting, for I am not a programmer), is figuring out how to do things that the scripting “rules” often prevents. One of these issues is dealing with UNC paths and Powershell confusing it with a regular expression, …

Continue reading »

Feb 26

Resource: Learning PowerShell

There are some really helpful resources on Microsoft’s Script Center for learning PowerShell. Resources: Windows PowerShell: Learn It Now Before It’s an Emergency (video) Windows PowerShell Owner’s Manual Hey, Scripting Guy! Blog VBScript to Windows PowerShell Conversion Guide A Task-Based Guide to Windows PowerShell Cmdlets Windows PowerShell Survival Guide PowerShell V3 Featured Articles Windows PowerShell …

Continue reading »

Feb 04

Powershell Code: Finding Orphaned Group Policy Objects

Group Policy is an interesting thing when it comes to Active Directory components. One part of the Group Policy (GPO) is stored in Active Directory, specifically in the CN=Policies,CN=System,DC=domain,DC=tld (for example: CN=Policies,CN=System,DC=metcorp,DC=org) which is replicated via AD replication. The other part is stored in SYSVOL which is replicated by File Replication Services (FRS). Here’s the …

Continue reading »

Jan 28

Powershell Parameter Parsing – How to Use a Single Parameter to Control Script Process Targeting

When I started using Powershell parameters, I had a parameter for everything. Now I have switched to using a single parameter for all relevant input and parse the parameter data for processing. All I’m doing is setting the parameter ConfigTarget and then parsing the input to see how the script should get the computer target …

Continue reading »

Older posts «

» Newer posts