Mick's IT Blogs

Mick's IT Blogs

18 September 2015

Font Installation Script

Posted By: Mick Pletcher - 12:48 PM












I had a bunch of fonts that need to be installed during the build of  the golden image. I wrote this script to install them as a task sequence, but also to be able to deploy the fonts easily through SCCM. This script will install all fonts of the specified font type from the specified directory location. All of the fonts you want installed are to be placed in the specified directory location. The script will  then read all files in that location and filter out for the specified font type. It will then install each font individually and output the status on whether it installed or not.

I did write an older font installation script back in 2012 in vbscript located in this blog posting.

You can download the script from here.


 <#       
      .NOTES  
      ===========================================================================  
       Created with:      SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.93  
       Created on:       9/18/2015 9:44 AM  
       Created by:       Mick Pletcher  
       Organization:        
       Filename:        install.ps1  
      ===========================================================================  
      .DESCRIPTION  
           This script will install all fonts of the specified font type from  
           the specified directory location. All of the fonts you want installed  
           are to be placed in the specified directory location. The script will  
           then read all files in that location and filter out for the specified  
           font type. It will then install each font individually and output  
           the status on whether it installed or not.   
 #>  
   
 function Get-RelativePath {  
      <#  
      .SYNOPSIS  
           Get-RelativePath  
      .DESCRIPTION  
           Defines the path which this script is being executed from  
      .EXAMPLE  
           $RelativePath = Get-RelativePath  
      #>  
        
      #Declare Local Variables  
      Set-Variable -Name RelativePath -Scope Local -Force  
        
      $RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent) + "\"  
      Return $RelativePath  
        
      #Cleanup Local Variables  
      Remove-Variable -Name RelativePath -Scope Local -Force  
 }  
   
 Function Install-Fonts {  
      <#  
      .SYNOPSIS  
           Install-Fonts  
      .DESCRIPTION  
           Installs all fonts in the designated source directory.  
      .EXAMPLE  
           Install-Fonts -SourceDirectory "c:\Fonts" -FontType "ttf"  
      #>  
        
      Param ([String]  
           $SourceDirectory,  
           [String]  
           $FontType)  
        
      #Define Local Variables  
      Set-Variable -Name File -Scope Local -Force  
      Set-Variable -Name Files -Scope Local -Force  
      Set-Variable -Name Fonts -Scope Local -Force  
      Set-Variable -Name i -Scope Local -Force  
      Set-Variable -Name sa -Scope Local -Force  
        
      $FontType = "*." + $FontType  
      $sa = new-object -comobject shell.application  
      $Fonts = $sa.NameSpace(0x14)  
      $Files = Get-ChildItem $SourceDirectory -Filter $FontType  
      For ($i = 0; $i -lt $Files.Count; $i++) {  
           $Output = $Files[$i].Name + "....."  
           Write-Host $Files[$i].Name"....." -NoNewline  
           $File = $Env:windir + "\Fonts\" + $Files[$i].Name  
           If ((Test-Path $File) -eq $false) {  
                $Fonts.CopyHere($Files[$i].FullName)  
                If ((Test-Path $File) -eq $true) {  
                     Write-Host "Installed" -ForegroundColor Yellow  
                } else {  
                     Write-Host "Failed" -ForegroundColor Red  
                }  
           } else {  
                Write-Host "Installed" -ForegroundColor Yellow  
           }  
      }  
        
      #Cleanup Local Variables  
      Remove-Variable -Name File -Scope Local -Force  
      Remove-Variable -Name Files -Scope Local -Force  
      Remove-Variable -Name Fonts -Scope Local -Force  
      Remove-Variable -Name i -Scope Local -Force  
      Remove-Variable -Name sa -Scope Local -Force  
 }  
   
 #Declare Local Variables  
 Set-Variable -Name RelativePath -Scope Local -Force  
   
 cls  
 $RelativePath = Get-RelativePath  
 Install-Fonts -SourceDirectory $RelativePath -FontType "ttf"  
 Install-Fonts -SourceDirectory $RelativePath -FontType "otf"  
   
 #Cleanup Local Variables  
 Remove-Variable -Name RelativePath -Scope Local -Force  

02 September 2015

Using PowerShell to retrieve the Bitlocker Recovery Key from Active Directory

Posted By: Mick Pletcher - 3:06 PM














I wanted an easy way to find the bitlocker recovery key in the even MBAM was down and as a backup. We use MBAM, but also use Active Directory as a backup for the keys. This script makes it easy to find the key without having to go into AD. I tested this script on user profiles both with and without permissions to the bitlocker recovery keys. If a user does not have permissions to view the key, then the script returns the message no key exists.

This script will prompt for the computer name. It will then display the bitlocker recovery key stored in Active Directory. In order for this to work correctly, you will need to install Remote Server Administration Tools and active the following feature: Remote Server Administration Tools-->
Role Administration Tools-->AD DS and AD LDS Tools-->Active Directory Module for Windows PowerShell.

You can download the script from here.


 <#       
      .NOTES  
      ===========================================================================  
       Created with:      SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.92  
       Created on:       8/25/2015 1:25 PM  
       Created by:       Mick Pletcher  
       Organization:        
       Filename:        BitlockerRecoveryKey.ps1  
      ===========================================================================  
      .DESCRIPTION  
           This script will prompt for the computer name. It will then display the  
     bitlocker recovery key. In order for this to work correctly, you will   
     need to install Remote Server Administration Tools and active the  
     following feature: Remote Server Administration Tools-->  
     Role Administration Tools-->AD DS and AD LDS Tools-->  
     Active Directory Module for Windows PowerShell.   
 #>  
   
 Function Get-ComputerName {  
   #Declare Local Variables  
   Set-Variable -Name ComputerName -Scope Local -Force  
   
   $ComputerName = Read-Host "Enter the computer name"  
   Return $ComputerName  
   
   #Cleanup Local Variables  
   Remove-Variable -Name ComputerName -Scope Local -Force  
 }  
   
 Function Get-BitlockeredRecoveryKey {  
   param ([String]$ComputerName)  
   
   #Declare Local Variables  
   Set-Variable -Name BitLockerObjects -Scope Local -Force  
   Set-Variable -Name BitLockerRecoveryKey -Scope Local -Force  
   Set-Variable -Name Computer -Scope Local -Value $null -Force  
   Set-Variable -Name System -Scope Local -Force  
   
   $BitLockerObjects = Get-ADObject -Filter { objectclass -eq 'msFVE-RecoveryInformation' }  
   foreach ($System in $BitLockerObjects) {  
     $System = $System.DistinguishedName  
     $System = $System.Split(',')  
     $System = $System[1]  
     $System = $System.Split('=')  
     $System = $System[1]  
     If ($System -eq $ComputerName) {  
       $Computer = Get-ADComputer -Filter {Name -eq $System}  
       $BitLockerRecoveryKey = Get-ADObject -Filter { objectclass -eq 'msFVE-RecoveryInformation' } -SearchBase $Computer.DistinguishedName -Properties 'msFVE-RecoveryPassword'  
       Write-Host "Computer Name:"$System  
       Write-Host "Bitlocker Recovery Key:"$BitLockerRecoveryKey.'msFVE-RecoveryPassword'  
     }  
   }  
   If ($Computer -eq $null) {  
     Write-Host "No recovery key exists" -ForegroundColor Red  
   }  
   
   #Cleanup Local Variables  
   Remove-Variable -Name BitLockerObjects -Scope Local -Force  
   Remove-Variable -Name BitLockerRecoveryKey -Scope Local -Force  
   Remove-Variable -Name Computer -Scope Local -Force  
   Remove-Variable -Name System -Scope Local -Force  
 }  
   
 #Declare Local Variables  
 Set-Variable -Name SystemName -Scope Local -Force  
   
 cls  
 Import-Module ActiveDirectory -Scope Global -Force  
 $SystemName = Get-ComputerName  
 Get-BitlockeredRecoveryKey -ComputerName $SystemName  
   
 #Cleanup Local Variables  
 Remove-Variable -Name SystemName -Scope Local -Force  
   

Copyright © 2013 Mick's IT Blogs™ is a registered trademark.