Import thumbnailphoto in AD from jpg

The script below will import JPG file as a thumbnailphoto in ActiveDirectory

$username = "p01001"
$jpgfile = "C:\PICTURE.jpg"
 

$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(&(objectclass=user)(objectcategory=person)(samAccountName=$username))"
$result = $search.FindOne()
 
if ($result -ne $null)
{
 $user = $result.GetDirectoryEntry()
 [byte[]]$jpg = Get-Content $jpgfile -encoding byte
 $user.put("thumbnailPhoto",  $jpg )
 $user.setinfo()
 Write-Host $user.displayname "updated"
}
else {Write-Host $user "Does not exist"}

~Pouyan

Creating and using Password Hashes and Secure Strings with Powershell

This is how you can generate a Secure String with powershell and use it in your scripts

$secureString = Read-Host -AsSecureString
ConvertFrom-SecureString $secureString | out-file c:tmpencrypted.txt
$newString = gc C:tmpencrypted.txt | ConvertTo-SecureString

Load the Secure string from file and use it in your script:

$securePassword = Get-Content "c:tmpencrypted.txt" | ConvertTo-SecureString

How to uninstall with msiexec using product id guid

You can find the product code by perusing the registry from this base key: HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall . Press F3 and search for your product name. (If it’s a 32-bit installer on a 64-bit machine, it might be under HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall instead).

Finally, you can find the product code also by using PowerShell:

get-wmiobject Win32_Product | 
Format-Table IdentifyingNumber, Name

NPinM

when you found the Guid ID you can use msiexec to uninstall the application

msiexec /x {A4BFF20C-A21E-4720-88E5-79D5A5AEB2E8}

 

PowerShell – How to find details of Operating System

There were several instances where I had to find details of the operating system using PowerShell. Here, I am providing several PowerShell snippets that return various details of the Operating System.

Name of the Operating System

PS C:> (Get-WmiObject Win32_OperatingSystem).Name

Is Operating System 32-bit or 64-bit

PS C:> (Get-WmiObject Win32_OperatingSystem).OSArchitecture

Name of the Machine

PS C:> (Get-WmiObject Win32_OperatingSystem).CSName

There are many more properties of the Operating System that are exposed. To obtain more details, run the following

PS C:> Get-WmiObject Win32_OperatingSystem | Get-Member

* Tested using PowerShell 3.0

Exchange 2013 management tools

Use unattended Setup mode to install the Exchange 2013 management tools

  1. Log on to the computer on which you want to install the Exchange 2013 management tools.
  2. Navigate to the network location of the Exchange 2013 installation files.
  3. At the command prompt, run the following command.
Setup.exe /Role:ManagementTools /IAcceptExchangeServerLicenseTerms

Disconnecting DirectAccess Clients on Windows Server 2012

DirectAccess provides seamless and transparent, always-on remote network connectivity. It does this without requiring action from the user. While this is an important feature and benefit of a DirectAccess remote access solution, it can also present a challenge for security administrators when a DirectAccess client device is lost or stolen. Continue reading Disconnecting DirectAccess Clients on Windows Server 2012

Powershell, WmiObject and a corrupt repository

For Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2, you can run winmgmt /verifyrepository from a command prompt. For Older OS like Windows XP and Windows Server 2003 run: WmiDiag tool with the checkconsistency option. For example: WmiDiag checkconsistency

If repository is found to be inconsistent, for Vista and newer, run from elevated command prompt:
Winmgmt /salvagerepository

Note this command will take the content of the inconsistent repository and merge it into the rebuilt repository if it is readable

If the above doesn’t work, then run:
Winmgmt /resetrepository

Note this will reset repository to the initial state when the OS was first installed

~pouyan