Unable to delete printer driver from Windows 7

In my case user was running on windows 7 x86 sp1, and was complaining that he can't print because printers doesn't exists on his computer. Printers should be installed using group policy preferences, so I have started to troubleshoot the problem. Printer spooler was stopped, and that was the reason why the user doesn't see printers in control panel. Printer spooler was stopping whenever group policy for installing printers was applying. So, I wanted to delete all unnecessary printer drivers that were installed. After opening Print Management mmc there were a lot of printers drivers that were not in use, and I started to remove drivers packages that were not in use. For the most of them removing was running smoothly, but there was one that was refusing to delete complaining that :

"The specified printer driver is currently in use. Failed to remove package ..."
I have tried a lot of the suggested solutions, but none of them helped me to delete the driver package. The only way that I have succeeded to delete the driver package was to rename the print processor from registry in my case HKLM\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Print Processors\ , and then delete the driver package from print management console.
Printers defined in GPO have successfully installed, and user was able to print documents.

Unable to reboot remote system

In my case remote workstation was XP and a user was unable to connect using remote desktop client, after disconnecting from the same computer couple of minutes ago. I have decided to initiate reboot of the client workstation using:
shutdown /f /r /m \\computername,
but the machine was hung up, and I tried to initiate same command again but the response was :
A system shutdown is in progress.(1115)
 
After waiting few more minutes the client workstation was not rebooted.
Because there was no one around the client machine to see what's happening on the monitor, and the user desperately needed to establish remote connection to the client workstation I have decided to kill the winlogon process. Using PSKill from PSTools suite I have executed:
pskill -t \\computername winlogon

and the remote workstation was rebooted. Note that killing winlogon process is nearly the same as pulling the plug on the machine.

Scripting Games 2012 Advanced Event 10

Advanced Event 10 :

<#
.DESCRIPTION
    This script creates csv log file for Processor counter set every 2 seconds (10 snapshots).
.LINK
    http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/13/the-2012-scripting-games-advanced-event-10-create-a-csv-log-file.aspx
#>
param (
[string[]]$Computers=$env:computername
)
foreach ($computer in $computers)
{
    $filepath = $env:userprofile + "\Documents\" + $Computer + "_processorCounters.csv"
        Get-Counter -ListSet processor -ComputerName $Computer |
        Get-Counter -ComputerName $Computer -SampleInterval 2 -MaxSamples 10 |
        Export-Counter -path $filepath -FileFormat CSV -Force
}

Scripting Games 2012 Advanced Event 9

Advanced Event 9 :


<#
.DESCRIPTION
    This script perform inventory and export data to xml.
.LINK
    http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/12/the-2012-scripting-games-advanced-event-9-perform-an-inventory.aspx
#>

function Create-XML
{
Param ([Parameter(Mandatory=$true,
   ValueFromPipeline=$true)]$object)

@"
<ComputerInfo>
"@
    foreach ($p in $object |Get-Member -type *Property )
    {
        $Name  = $p.Name
        $Value = $Object.$Name   
@"
`t<$Name>$Value</$Name>`n
"@
     }
@"
</ComputerInfo>
"@
}

function HumanReadSize
{
    Param ([long]$Size)
if ($Size -ge 1Gb )
{
return ("{0:N2}" -f ($Size / 1Gb) + " GigaBytes")
}
elseif ($Size -ge 1Mb )
{
return ("{0:N2}" -f ($Size / 1Mb ) + " MegaBytes")
}
elseif ($Size -ge 1Kb )
{
return ("{0:N2}" -f ($Size / 1Kb ) + " KiloBytes")
}
elseif (($Size -ge 0 ) -and ($Size -lt 1Kb))
{
return ("{0:N0}" -f ($Size) + " Bytes")
}
}

$sum=0
$os= Get-WmiObject Win32_OperatingSystem
$comp = Get-WmiObject win32_ComputerSystem
$procs = Get-WmiObject win32_Processor
$nets = Get-WmiObject  win32_networkadapter -Filter "netenabled = true"
Get-WmiObject win32_physicalmemory | where {( $_.typedetail -ne 4096 )} | foreach {$sum += $_.capacity }

    $output = New-Object PSObject
    $output | Add-Member noteproperty ComputerName ($comp.Name)
    $output | Add-Member noteproperty DomainName ($comp.Domain)
    $output | Add-Member noteproperty Manufacturer ($comp.Manufacturer)
    $output | Add-Member noteproperty ComputerModel ($comp.Model)
    $output | Add-Member noteproperty NumberofProcessors ($comp.NumberOfProcessors)
    $output | Add-Member noteproperty Numberofcores ($comp.NumberOfLogicalProcessors)
$i=1
foreach ($proc in $procs)
{
   
    $output | Add-Member noteproperty "Speedofprocessors$i"  ($proc.MaxClockSpeed)
    $output | Add-Member noteproperty "ProcessorID$i" ($proc.ProcessorID)
    $i +=1   
}
$b=1
foreach ($net in $nets)
{
    $output | Add-Member noteproperty "MACAddress$b" ($net.MACAddress)
    $b += 1
}

    $output | Add-Member noteproperty Version ($os.Version)
    $output | Add-Member noteproperty Memory (HumanReadSize $sum)

$filepath = $env:userprofile + "\Documents\" + ($comp.Name) + "." + ($comp.Domain) + "." + (Get-date).tostring("yyyyMMdd") + ".xml"
$output | create-xml | Out-file $filepath

Scripting Games 2012 Advanced Event 8

Advanced Event 8 :

<#
.DESCRIPTION
    This script can enable and (or) disable wireless or ethernet adapter to prevent bridging on laptop computers.
.LINK
    http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/11/the-2012-scripting-games-advanced-event-8-enable-network-adapters.aspx
#>

function get-netadapter
{
  param ([string]$nettype= "%", $isEnabled=$null)
    if ($isenabled -eq $null)
    {
      $filter ="name like '$nettype'"
    }
    else
    {
      $filter ="name like '$nettype' and netenabled=$isenabled"
    }   
   return Get-WmiObject win32_networkadapter -Filter $filter
}

function enableadapter
{
  param ($enable=$true, $neta, $prev=$false)
    #enable adapters
    if ($enable)
    {
      if ($neta.count -gt 1)
      {
     
         foreach ($adapter in $neta)
         {
            do
            {
                $choice = Read-Host $adapter.description  " Enable Yes/No ?"
            }
            until ($choice -eq "yes" -or $choice -eq "no")
           
             If ($Choice -eq "yes")
             {
                if (!($prev))
                {
                    $adapter.enable()
                }
                else
                {
                    # for pre-vista os, even though netsh is working on post vista oss,
                    #it is fun using new method for these oss .enable() or .disable()
                    netsh interface set interface "$($adapter.netconnectionID)" ENABLED
                }
               
                return
             }   
          }
       }
       else
       {
          if (!($prev))
          {
             $neta.enable()
          }
          else
          {
                   
              netsh interface set interface "$($neta.netconnectionID)" ENABLED
           }
       }
   
    }
    #disable adpaters
    else
    {
      foreach ($adapter in $neta)
      {
     
                if (!($prev))
                {
                    $adapter.disable()
                }
                else
                {
                    netsh interface set interface "$($adapter.netconnectionID)" DISABLED
                }
      }
     }
}

    $identity  = [System.Security.Principal.WindowsIdentity]::GetCurrent()
    $principal = New-Object System.Security.Principal.WindowsPrincipal( $identity )
   
        if (!($principal.IsInRole( [System.Security.Principal.WindowsBuiltInRole]::Administrator )))
        {
            write-host "Warning: You're not running this script using elevated shell. You will not be able to run this script without administrative permission."
            exit
   
        }
       
   $os = Get-WmiObject Win32_OperatingSystem
    if ($os.version -match "5.")
    {
        $prevista=$true
    }
    else
    {
        $prevista=$false
    }
   
    $comp = Get-WmiObject win32_ComputerSystem
    #It is a laptop   
     if ($comp.PCSystemType -eq 2)
     {
         #check for enabled wireless and ethernet adapters
         $wless=@()
         $wless = @(get-netadapter "%wireless%" $true)
         $ether=@()
         $ether = @(get-netadapter "%ethernet%" $True)
            #wireless adapters not enabled and ethernet adpaters enabled
            if ($wless.Count -eq 0 -and $ether.Count -gt 0)
            { 
                #disable ethernet adapters
                enableadapter $false $ether $prevista
                #enable wireless adapter
                enableadapter $True (get-netadapter "%wireless%" $false) $prevista
   
            }
            #wireless adapter(s) enabled and ethernet adpaters disabled
            elseif ($wless.Count -gt 0 -and $ether.Count -eq 0)
            {
               #disable wireless adapters
                enableadapter $false $wless $prevista
                #enable ethernet adapter
                enableadapter $True (get-netadapter "%ethernet%" $false) $prevista
            }
            # no ethernet or wireless enabled
            elseif ($wless.Count -eq 0 -and $ether.Count -eq 0)
            {
                do
                {
                    $choice = Read-Host "Ethernet and Wireless adapters are disabled.Enable Wireless adapter Yes/No ?"
                }
                until ($choice -eq "yes" -or $choice -eq "no")
           
                If  ($choice -eq "yes")
                {
                    Write-Host "Enabling wireless adapters ..."
                    enableadapter $True (get-netadapter "%wireless%" $false) $prevista
                }
                else
                {
                    Write-Host "Enabling ethernet adapters ..."
                    enableadapter $True (get-netadapter "%ethernet%" $false) $prevista
                }
      
            }
            # ethernet and wireless enabled
            elseif ($wless.Count -gt 0 -and $ether.Count -gt 0)
            {
                do
                {
                    $choice = Read-Host "Ethernet and Wireless adapters are enabled.Disable Wireless adapter Yes/No ?"
                }
                until ($choice -eq "yes" -or $choice -eq "no")
           
                If  ($choice -eq "yes")
                {
                    Write-Host "Disabling wireless adapters ..."
                    enableadapter $false (get-netadapter "%wireless%" $true) $prevista
                }
                else
                {
                    Write-Host "Disabling ethernet adapters ..."
                    enableadapter $false (get-netadapter "%ethernet%" $true) $prevista
                }
      
            }
        }
        else
        {
            Write-Host "This script is only for laptops !"
        }

How to check EMBG (Unique Master Citizen Number) using regex

In this post, I will share my implementation of how to check if some number looks like EMBG or Unique Master Citizen Number. For those of yo...