Saturday, October 25, 2014

PlanetSide 2 All Access Members Station Cash Trip Wire

SOE All Access Gotcha

SOE's Middle Finger to you - the customer (view link below)
Membership Link

FAQ Questions 9 - 12 in Graphic above

This post is more of a good to know for people who pay for their PlanetSide 2 account. You would think with all of the damn rewards that they offer you to be a member, they would automatically load your 500 SC directly into your account like they used to do when I first signed up, but some jaggoff (or group of jaggoffs) I am sure decided that members have to actually sign in to get their SC. That's bullcrap as far as I am concerned. SOE apparently doesn't care about it's adult professional players/gamers out there because I sometimes go 3 or more months without playing any video games when I am busy working on a huge project at work. I'm lucky if I can sleep, let alone log into my PS2 account so that I can click on a "claim" button.

It wasn't apparent to me that my SC balance hadn't increased until after I actually had time to play again and it had been like 4 months. SOE screwed me out of 2000 SC that I PAID for because they decided to change their account policies.

This is equivalent to telling an employee that works for a company, that unless they ask for their paycheck each month, they won't get one - even though you are signed up for direct deposit and to make matters worse you pay your employer to work there.

Therefore I have every right to point at SOE and call them a bunch of assholes for pulling this. You guys are dicks. Thanks for the so called encouragement to play more, but no thanks - I will play the goddamn game when I feel like it BECAUSE IT IS A VIDEO GAME NOT A JOB.

This is the first time I have paid for membership for a game. Granted I love playing the game, but I do not think a PAYING member should be CHASTISED and PUNISHED for not playing the game. That is a load of crap that some idiot in SOE's business department came up with to increase profit margins. That's dirty.


Sunday, October 5, 2014

Recycle Application Pool using WMI via Powershell

Introduction

I handle the builds for a particular piece of software at my place of work. I am responsible for deploying any new versions of code to all environments; including but not limited to: Development (Dev), Quality Assurance (QA), Staging aka User Acceptance Testing (UAT) and most importantly Production (Prod). When I was given this responsibility there was no existing structure or procedure for getting the job done. A build could take an hour or longer to execute because files were being copied in the worst possible way imaginable - by hand... In this day and age there is no reason for anyone, let alone a developer, to be doing any type of repetitive zero brain function task manually. Therefore I did what I always do when I see a pattern and a way to make it faster, I wrote a program. What used to take over an hour to do I can now do in less than a minute. I'm not exaggerating.

Windows Management Instrumentation (WMI)

The goal here for me was to copy a published version of code to multiple destinations and then recycle the application pool for each site. I never had to do remote IIS operations before - enter WMI. WMI, from what I understand, is both loved and hated by all. It can be buggy and sometimes it works just fine. In my particular case it worked wonderfully and continues to work very well to this day. If you want to read up on it take a look here.

Considerations

  1. WMI is only as powerful as to what you have access too. Just like you need permissions to alter files and folders on a remote system via UNC file paths - this is no different, WMI will do nothing for you if you do not have the proper access on the target system.
  2. WMI must be enabled on your system (host running the script) and the target system (web server) in order for WMI to work. WMI runs as a service.
  3. The script I am sharing will only work with IIS7 and greater. IIS6 uses something different and older obviously. I strongly suggest moving to IIS7.5 at this point. For IIS6 view the example here.

Powershell Script Functions

I have three functions to share and they are as follows:
  1. GetApplicationPools - literally get all application pools on a target web server
  2. RecycleApplicationPools - recycle a specific list of application pools on a target web server
  3. ApplicationPoolStateDescription - translate the application pool state unsigned integer into a human readable string
You will see below that for the Authentication argument it is hardcoded to the magic number 6. I don't accept using magic numbers, but for this case I am giving it a pass since this is a script. The 6 represents PacketPrivacy apparently. The credentials being used for the WMI execution are purely based on who is running the script. If you start Powershell as an Administrator - then that session will have Administrative privileges and your identity will be shoved along for all commands executed. Get-WmiObject -Authentication

Get All Available Application Pools

#Get all application pool names for the specified server name
#Returns the names as an Array
function GetApplicationPools
{
 param([string]$server)
 
 #http://theolddogscriptingblog.wordpress.com/2012/07/09/powershell-iis-and-driving-myself-nuts/
 $lst = Get-WmiObject -Namespace 'root\webadministration' `
      -Class ApplicationPool `
      -ComputerName $server `
      -Authentication 6
      
 $arrNames = @();

 #optional loop for additional filtering
 foreach($p in $lst)
 {
  #if($p.Name.ToLower().Contains("pattern") -eq $true)
  $arrNames = $arrNames + @($p.Name)
 }

 return $arrNames
}

Recycle Specified List of Application Pools

#Get all application pool names for the specified server name
function RecycleApplicationPools
{
 param([string]$server, [Array]$poolNames)
 
 if($arrPools.Length -gt 0)
 {
  (write-host ("Restarting Application Pools") -foregroundcolor "yellow" -backgroundcolor "black")

  [string]$strState = [string]::Empty;
  $pool = $null

  foreach($p in $poolNames)
  {
   #Using ApplicationPool WMI object
   #http://msdn.microsoft.com/en-us/library/ms690608(v=vs.90).aspx
   $pool = Get-WmiObject -Namespace 'root\webadministration' `
        -Class ApplicationPool `
        -ComputerName $server `
        -Authentication 6 `
        -Filter ('Name="' + $p + '"')

   $pool.Recycle();    
   
   $strState = ApplicationPoolStateDescription -state $pool.GetState().ReturnValue
   
   (write-host ("`t" + $pool.Name + " = " + $strState) -foregroundcolor "cyan" -backgroundcolor "black")
  }
 }
 else
 {
  (write-host ("No application pools were restarted because the provided list was empty") -foregroundcolor "red" -backgroundcolor "black")
 }
}

Translate Application Pool State Unsigned Integer into Human Readable String

#Get the application pool's state's description
#Converts UInt to a string equivalent
#Returns the string
function ApplicationPoolStateDescription
{
 param([uint32]$state)

 [string]$strState = [string]::Empty;
 
 #GetState() Method's output as integer to string
 #http://msdn.microsoft.com/en-us/library/ms691445(v=vs.90).aspx
 switch($state)
 {
  0 { $strState = "starting" }
  1 { $strState = "started" }
  2 { $strState = "stopping" }
  3 { $strState = "stopped" }
  4 { $strState = "unknown" }
  default { $strState = "unknown2: " + $state.ToString() }
 }
 
 return ,$strState;
}

Conclusion

Don't work harder than you have to. If you can automate a redundant process, you should - you aren't gaining anything from doing it manually repeatedly other than muscle memory and a large loss of time. My deployments take less than a minute to do now. Work smart - not hard.

Resources