One-Liner: Setting Default Web Proxy for Windows Server 2003 and 2008

Our labs run a mix of Windows Server 2003 and 2008.  Setting a proxy in Windows Server 2003 is as follows: CMD> proxycfg.exe proxy.fqdn *.first.excluded.domain;*.second.excluded.domain;* Windows Server 2008 doesn’t have proxycfg.exe, so the command is: CMD> netsh.exe winhttp set proxy proxy-server=”proxy.fqdn” bypass-list=”*.first.excluded.domain;*.second.excluded.domain;*” Of course, Windows Server 2003’s version of netsh.exe doesn’t support setting the proxy…


PowerShell for Non-N00bs: Formatting Time With RegEx

So, last episode we learned how to format the output of a LastBootUpTime property from the WIN32_OperatingSystem WMI query to something human readable using WMI.  What if that didn’t exist?   PSH> (Get-WmiObject -Query ‘SELECT LastBootUpTime FROM Win32_OperatingSystem’).LastBootUpTime20090712112652.125000-420 So, we have this ugly string.  Hhow do we convert it to something we can use (namely, a string…


PowerShell for Non-N00bs: System Uptime Via WMI

Getting the last time a system was rebooting is pretty easy from WMI.  From this half-decade old post, we get the two key bits: the LastBootUptTimem property of the Win32_OperatingSystem WMI class.  In PowerShell, it looks like this: PSH> (Get-WmiObject -Query ‘SELECT LastBootUpTime FROM Win32_OperatingSystem’).LastBootUpTime20090712112652.125000-420 The output is a little hard to read.  PSH> $lastBootUpTimeWMIObject = (Get-WmiObject -Query ‘SELECT…


PowerShell for Non-N00bs: Adding a User to a Group (with Script)

Here’s the one-liner: ([ADSI]”WinNT://$computerName/$localGroupName,group”).Add(“WinNT://$domainName/$userName”); But a script may be more useful for execution.          Add-UserToGroup.ps1


One-Liner: Getting This Computer’s Serial Number

The computer’s serial number can be very useful.  Among other things, many manufactuers’ support sites keep record of their machine’s serial numbers to serve the right drivers for downloads. CMD> wmic bios get serialnumberSerialNumberABCDEF12345 Wmic is the command line executable for performing simple WMI queries.  BIOS is wmic’s shorthand for Win32_bios.  The PowerShell equivalent would…


PowerShell One-Liner: Removing a System Variable

We’ve learned we can create system variables on a remote machine with the setx.exe command: PSH> setx -m remote.machine My_System_Variable VariableData However, setx doesn’t give us a way to remove the variable. PSH> (new-object -com“system”).remove(“My_System_Variable”) Why we have non-orthogonal commands like this is beyond me, but here at least is a way to work…


PowerShell for N00bs: $env:temp vs. %TEMP%

A while ago, we snuck in something. PSH> dir $env:temp | less $env:temp is PowerShell’s way of accessing the original environment variables, the stuff we get when we type ‘set’ at a cmd.exe prompt.  ‘set’ in PowerShell is an alias for Set-Variable, so it doesn’t do the same thing.  To get the same output, type…


PowerShell for Non-N00bs: Certificates Installed on a Remote Host

Okay, we know how to examine when a certificate file expires.  How about whne a certificate that’s installed on a computer? PSH> $computer = ‘’ PSH> $ro = [System.Security.Cryptography.X509Certificates.OpenFlags]”ReadOnly”   PSH> $cu =[System.Security.Cryptography.X509Certificates.StoreLocation]”LocalMachine”  PSH> $c = new-object System.Security.Cryptography.X509Certificates.X509Store(“\\$computer\CA”,$cu)  PSH> $c.Open($ro) PSH> $c.CertificatesThumbprint                                Subject———-                                ——-FEE449EE0E3965A5246F000E87FDE2A065FD89D4  CN=Root Agency980F61CB05442A1D40D15A8C7EF792A89EABB434  CN=Microsoft Test PCA, O=Microsoft…8B24CD8D8B58C6DA72ACE097C7B1E3CEA4DC3DC6 …7B02312BACC59EC388FEAE12FD277F6A9FB4FAC1  CN=VeriSign Class 2…


PowerShell for Non-N00bs: Certificate Files

Let’s say we have a certfiicate file.  (“We have a certificate file.”  Yuck-yuck, haw-haw.)  When does it expire? PSH> $certObject = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $pathToCertFile; PSH> $certObject.NotAfterWednesday, January 21, 2011 12:49:18 PM  PS> $certObject.NotAfter | Get-Member    TypeName: System.DateTime Name                 MemberType     Definition —-                 ———-     ———- Add                  Method         System.DateTime Add(TimeSpan value) AddDays              Method         System.DateTime AddDays(Double value) AddHours            …