PowerShell - scheduled task to hide users disabled in AD from the Global Address List

 daily scheduled task to hide users disabled in AD from the Global Address List

$mailboxes = get-user | where {$_.UserAccountControl -like '*AccountDisabled*' -and $_.RecipientType -eq 'UserMailbox' } | get-mailbox  | where {$_.HiddenFromAddressListsEnabled -eq $false}

foreach ($mailbox in $mailboxes) { Set-Mailbox -HiddenFromAddressListsEnabled $true -Identity $mailbox }

Powershell - Export Printer Information to and Excel document

Export Printer Information to and Excel document

Have Fun... lots of tricks here  :)

Param (
    [string]$Printservers = "PRINTSERVER"

# Create new Excel workbook
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
$Sheet.Name = "Printer Inventory"
$Sheet.Cells.Item(1,1) = "Print Server"
$Sheet.Cells.Item(1,2) = "Printer Name"
$Sheet.Cells.Item(1,3) = "Location"
$Sheet.Cells.Item(1,4) = "Comment"
$Sheet.Cells.Item(1,5) = "IP Address"
$Sheet.Cells.Item(1,6) = "Driver Name"
$Sheet.Cells.Item(1,7) = "Driver Version"
$Sheet.Cells.Item(1,8) = "Driver"
$Sheet.Cells.Item(1,9) = "Shared"
$Sheet.Cells.Item(1,10) = "Share Name"
$intRow = 2
$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 40
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True

# Get printer information
ForEach ($Printserver in $Printservers)
{   $Printers = Get-WmiObject Win32_Printer -ComputerName $Printserver
    ForEach ($Printer in $Printers)
        if ($Printer.Name -notlike "Microsoft XPS*")
            $Sheet.Cells.Item($intRow, 1) = $Printserver
            $Sheet.Cells.Item($intRow, 2) = $Printer.Name
            $Sheet.Cells.Item($intRow, 3) = $Printer.Location
            $Sheet.Cells.Item($intRow, 4) = $Printer.Comment
            If ($Printer.PortName -notlike "*\*")
            {   $Ports = Get-WmiObject Win32_TcpIpPrinterPort -Filter "name = '$($Printer.Portname)'" -ComputerName $Printserver
                ForEach ($Port in $Ports)
                    $Sheet.Cells.Item($intRow, 5) = $Port.HostAddress
            $Drivers = Get-WmiObject Win32_PrinterDriver -Filter "__path like '%$($Printer.DriverName)%'" -ComputerName $Printserver
            ForEach ($Driver in $Drivers)
                $Drive = $Driver.DriverPath.Substring(0,1)
                $Sheet.Cells.Item($intRow, 7) = (Get-ItemProperty ($Driver.DriverPath.Replace("$Drive`:","\\$PrintServer\$Drive`$"))).VersionInfo.ProductVersion
                $Sheet.Cells.Item($intRow,8) = Split-Path $Driver.DriverPath -Leaf
            $Sheet.Cells.Item($intRow, 6) = $Printer.DriverName
            $Sheet.Cells.Item($intRow, 9) = $Printer.Shared
            $Sheet.Cells.Item($intRow, 10) = $Printer.ShareName
            $intRow ++
    $WorkBook.EntireColumn.AutoFit() | Out-Null

$intRow ++
$Sheet.Cells.Item($intRow,1) = "Printer inventory completed"
$Sheet.Cells.Item($intRow,1).Font.Bold = $True
$Sheet.Cells.Item($intRow,1).Interior.ColorIndex = 40
$Sheet.Cells.Item($intRow,2).Interior.ColorIndex = 40

Powershell - Add a picture for a user in AD

Add a picture for a user in AD

fun and fast...........

Set-ADUser BBunny -Replace @{thumbnailPhoto=([byte[]](Get-Content "C:\temp\BBunny.jpg" -Encoding byte))}

you can allways add a bunch of users this way

$users = @(
$list += @()
foreach ($user in $users) {
Set-ADUser $user -Replace @{thumbnailPhoto=([byte[]](Get-Content "C:\temp\$user.jpg" -Encoding byte))}

The most useful websites and web apps

The Most Useful Websites and Web Apps

ctrlq.org/screenshots – for capturing screenshots of web pages on mobile and desktops.
dictation.io – online voice recognition in the browser itself.
Most Useful Websiteszerodollarmovies.com – find full-length movies on YouTube.
screenr.com – record movies of your desktop and send them straight to YouTube.
goo.gl – shorten long URLs and convert URLs into QR codes.
unfurlr.come – find the original URL that’s hiding behind a short URL.
qClock – find the local time of a city using Google Maps.
copypastecharacter.com – copy special characters that aren’t on your keyboard.
codeacademy.com – the best place to learn coding online.
lovelycharts.com – create flowcharts, network diagrams, sitemaps, etc.
iconfinder.com – find icons of all sizes.
office.com – download templates, clipart and images for your Office documents.
followupthen.com – the easiest way to setup email reminders.
jotti.org – scan any suspicious file or email attachment for viruses.
wolframalpha.com – gets answers directly without searching   – see more wolfram tips.
printwhatyoulike.com – print web pages without the clutter.
ctrlq.save – save online files to Dropbox or Google Drive directly.
ctrql.rss – a search engine for RSS feeds.
e.ggtimer.com – a simple online timer for your daily needs.
coralcdn.org – if a site is down due to heavy traffic, try accessing it through coral CDN.
random.org – pick random numbers, flip coins, and more.
pdfescape.com – lets you can quickly edit PDFs in the browser itself.
tubemogul.com – simultaneously upload videos to YouTube and other video sites.
scr.im – share you email address online without worrying about spam.
spypig.com – now get read receipts for your email.
myfonts.com/WhatTheFont – quickly determine the font name from an image.
google.com/webfonts – a good collection of open source fonts.
regex.info – find data hidden in your photographs – see more EXIF tools.
livestream.com – broadcast events live over the web, including your desktop screen.
iwantmyname.com – helps you search domains across all TLDs.
homestyler.com – design from scratch or re-model your home in 3d.
join.me – share you screen with anyone over the web.
onlineocr.net – recognize text from scanned PDFs – see other OCR tools.
flightstats.com – Track flight status at airports worldwide.
wetransfer.com – for sharing really big files online.
hundredzeros.com – the site lets you download free Kindle books.
polishmywriting.com – check your writing for spelling or grammatical errors.
marker.to – easily highlight the important parts of a web page for sharing.
typewith.me – work on the same document with multiple people.
whichdateworks.com – planning an event? find a date that works for all.
everytimezone.com – a less confusing view of the world time zones.
gtmetrix.com – the perfect tool for measuring your site performance online.
noteflight.com – print music sheets, write your own music online (review).
imo.im – chat with your buddies on Skype, Facebook, Google Talk, etc. from one place.
translate.google.com – translate web pages, PDFs and Office documents.
kleki.com – create paintings and sketches with a wide variety of brushes.
similarsites.com – discover new sites that are similar to what you like already.
wordle.net – quick summarize long pieces of text with tag clouds.
bubbl.us – create mind-maps, brainstorm ideas in the browser.
kuler.adobe.com – get color ideas, also extract colors from photographs.
liveshare.com – share your photos in an album instantly.
lmgtfy.com – when your friends are too lazy to use Google on their own.
midomi.com – when you need to find the name of a song.
google.com/history – see your past searches, also among most important Google URLs
bing.com/images – automatically find perfectly-sized wallpapers for mobiles.
faxzero.com – send an online fax for free – see more fax services.
feedmyinbox.com – get RSS feeds as an email newsletter.
ge.tt – qiuckly send a file to someone, they can even preview it before downloading.
pipebytes.com – transfer files of any size without uploading to a third-party server.
tinychat.com – setup a private chat room in micro-seconds.
privnote.com – create text notes that will self-destruct after being read.
boxoh.com – track the status of any shipment on Google Maps – alternative.
mondrian.io – create vector drawings in the browser
draw.io – create diagrams and flowcharts in the browser, export your drawings to Google Drive and Dropbox.
downforeveryoneorjustme.com – find if your favorite website is offline or not?
ewhois.com – find the other websites of a person with reverse Analytics lookup.
whoishostingthis.com – find the web host of any website.
labnol.org – software tutorials and how-to guides.
disposablewebpage.com – create a temporary web page that self-destruct.
urbandictionary.com – find definitions of slangs and informal words.
seatguru.com – consult this site before choosing a seat for your next flight.
unsplash.com – download images absolutely free.
zoom.it – view very high-resolution images in your browser without scrolling.
scribblemaps.com – create custom Google Maps easily.
alertful.com – quickly setup email reminders for important events.
picmonkey.com – Picnik is offline but PicMonkey is an even better image editor.
formspring.me – you can ask or answer personal questions here.
sumopaint.com – an excellent layer-based online image editor.
snopes.com – find if that email offer you received is real or just another scam.
typingweb.com – master touch-typing with these practice sessions.
mailvu.com – send video emails to anyone using your web cam.
timerime.com – create timelines with audio, video and images.
stupeflix.com – make a movie out of your images, audio and video clips.
safeweb.norton.com – check the trust level of any website.
teuxdeux.com – a beautiful to-do app that looks like your paper dairy.
deadurl.com – you’ll need this when your bookmarked web pages are deleted.
minutes.io – quickly capture effective notes during meetings.
youtube.com/leanback – Watch YouTube channels in TV mode.
youtube.com/disco – quickly create a video playlist of your favorite artist.
talltweets.com – Send tweets longer than 140 characters.
pancake.io – create a free and simple website using your Dropbox account.
builtwith.com – find the technology stack to know everything about a website.
woorank.com – research a website from the SEO perspective.
mixlr.com – broadcast live audio over the web.
radbox.me – bookmark online videos and watch them later (review).
tagmydoc.com – add QR codes to your documents and presentations (review).
notes.io – the easiest way to write short text notes in the browser.
ctrlq.org/html-mail – send rich-text mails to anyone, anonymously.
fiverr.com – hire people to do little things for $5.
otixo.com – easily manage your online files on Dropbox, Google Docs, etc.
ifttt.com – create a connection between all your online accounts.
Changelog and Updates

Windows PowerShell Scripting and Toolmaking

Course 55039A:Windows PowerShell Scripting and Toolmaking

This five-day instructor-led course is intended for IT Professionals who have a working knowledge of Windows PowerShell 3.0 techniques and technologies, and who want to build reusable tools by using Windows PowerShell 3.0. Students of this course may administer a wide variety of server and client products and technologies that offer Windows PowerShell integration, including Microsoft Exchange Server, Microsoft Windows Active Directory Domain Services, Microsoft SharePoint Server, and more. This course focuses on the Windows PowerShell scripting language, and on the concepts and techniques needed to produce reusable, professional tools.
Audience profile

This course is intended for administrators that have little or no programming experience, but who have a working knowledge of Windows PowerShell and who are able to use Windows PowerShell to run complex, interactive commands.
At course completion
After completing this course, students will be able to:

  • Design tools, including input requirements, output requirements, and functional requirements.
  • Write tools, including scripting, parameterizing commands, and providing verbose output.
  • Debug tools and provide error handling within tools.
  • Combine tools into script and manifest modules.
  • Create custom formatting views.
  • Create tools that are consistent in naming and operation with native Windows PowerShell tools



Open up your Microsoft.PowerShellISE_profile.ps1 file and add the following lines:

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Run with -Verbose', { Invoke-Expression -Command ". '$($psISE.CurrentFile.FullPath)' -Verbose" }, 'Ctrl+F5') | Out-Null
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Run with -Debug',   { Invoke-Expression -Command ". '$($psISE.CurrentFile.FullPath)' -Debug" }, 'Ctrl+F6') | Out-Null

 restart ISE you should see the options under the Add-Ons menu.

Spiceworks Link



updating windows and control when the system restarts.
Thanks to Rönnkvist
Copy the following files to %ProgramFiles%\RebootIfNeeded
RebootIfNeeded.ps1 – Copy script below
hstart64.exe – Download from http://www.ntwind.com/software/hstart.html (needed to hide the scheduled task completely)
ShutdownTool.exe – Download from http://blog.coretech.dk/kea/new-version-of-the-coretech-shutdown-tool/ (you can find the latest version in the comments)
Create a Scheduled Task that runs once or twice every day (I have it set at 08:00 and 13:00 every weekday), and on that task create an with the following configuration:
Program: %ProgramFiles%\RebootIfNeeded\hstart64.exe
Arguments: /NOCONSOLE /WAIT “”%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe” -NoLogo -NoProfile -NonInteractive -File “%ProgramFiles%\RebootIfNeeded\RebootIfNeeded.ps1″”

    $maxBootAgeDays = 35,
    $restartTimeOut = (9 * 60), # 9 hours
    $restartMaxPostpone = (48 * 60), # 48 hours
    $restartDescriptions = @{
        "en-US" = "Your computer needs to restart to receive the latest updates.";
    $defaultLanguage = "en-US"
Function Get-PendingReboot {
    # Local HKLM
    $HKLM = [UInt32] "0x80000002"
    $wmiRegistry = [WMIClass] "\\.\root\default:StdRegProv"
    $PendingReboot = $false
    # CBS - Reboot Required ?
    $RegSubKeysCBS = $wmiRegistry.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")
    if ($RegSubKeysCBS.sNames -contains "RebootPending") {
        Write-Verbose "Component Based Servicing have a reboot pending"
        $PendingReboot = $true
    # Windows Update - Reboot Required?
    $RegistryWUAU = $wmiRegistry.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")
    if ($RegistryWUAU.sNames -contains "RebootRequired") {
        Write-Verbose "Windows Update have a reboot required"
        $PendingReboot = $true
    ## Pending FileRenameOperations ?
    $RegSubKeySM = $wmiRegistry.GetMultiStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\","PendingFileRenameOperations")
    If ($RegSubKeySM.sValue) {
        $RegSubKeySM.sValue | ForEach-Object { 
            If ($_.Trim() -ne '') {
                Write-Verbose "Pending FileRename operation: $($_)"
        $PendingReboot = $true
    # ConfigMgr - Pending reboot ?
    TRY {
        $CCMClientSDK = Invoke-WmiMethod -NameSpace "ROOT\ccm\ClientSDK" -Class "CCM_ClientUtilities" -Name "DetermineIfRebootPending" -ErrorAction Stop
        If ($CCMClientSDK.IsHardRebootPending -or $CCMClientSDK.RebootPending) {
            Write-Verbose "ConfigMgr have reboot pending"
            $PendingReboot = $true
    } CATCH {
        Write-Verbose "Cant talk to ConfigMgr Agent"
    Write-Verbose "Pending reboot: $($PendingReboot)"
    Return $PendingReboot
Function Check-OldBootAge {
    PARAM (
        $maxAgeDays = 35
    $BootTime = Get-WmiObject  Win32_Operatingsystem
    [Int]$days = (New-TimeSpan -Start $boottime.ConvertToDateTime($boottime.LastBootUpTime) -End (Get-Date)).TotalDays
    if ($days -ge $maxAgeDays) {
        Write-Verbose "Boot age is $($days) days (more than $($maxBootAgeDays)), reboot required"
        Return $true
    } else {
        Write-Verbose "Boot age is $($days) days (less than $($maxBootAgeDays))"
        Return $false
    Return $days
Function Get-UserLanguage {
    Return [String] ([System.Threading.Thread]::CurrentThread).CurrentUICulture.Name
# ------------------------------------------------------------------------------------------------------------
# Main script
if ( (Get-WmiObject -Query "SELECT ProductType FROM Win32_OperatingSystem").ProductType -eq 1) {
    If ( (Get-Process "ShutdownTool" -ErrorAction SilentlyContinue) ) {
        Write-Host "Already running ShutdownTool"
    } else {
        If ((Check-OldBootAge -maxAgeDays $maxBootAgeDays) -or (Get-PendingReboot)) {
            Write-Host "Reboot is required, calling restart utility"
            $userLanguage = Get-UserLanguage
            Write-Verbose "Language: $($userLanguage)"
            # Find description
            $Description = $restartDescriptions[$userLanguage]
            if ($Description -eq $null) {
                $Description = $restartDescriptions[$defaultLanguage]
            $timeOutSeconds = ($restartTimeOut*60) - 1
            Write-Verbose "Restart timeout: $($timeOutSeconds) seconds"
            Write-Verbose "Max postpone: $($restartMaxPostpone) minutes"
            Write-Verbose "Description: $($Description)"
            If ((Test-Path ".\ShutdownTool.exe") -eq $false) {
                Throw "Cant find ShutdownTool.exe"
            } else {
                Write-Verbose "Calling restart with ShutdownTool"
                .\ShutdownTool.exe /g:$userLanguage /d:"$Description" /t:$timeOutSeconds /m:$restartMaxPostpone /r /c
            # /g - Language
            # /d - description
            # /t - countdown in sec
            # /m - max postpone in min
            # /r - reboot instead of shutdown
            # /c - force & remove abort-btn
} else {
    Write-Verbose "Not a client OS"
# Done!

Spiceworks Link



Add-AdThumbnailPhoto {
    PARAM (
        [ValidateScript({Test-Path $_ -PathType Leaf})] [string] $PicturePath,
    If (!(Test-IsModuleLoaded "ActiveDirectory")) {
        Throw "You need to run: Import-Module ActiveDirectory"
    Write-Verbose "Adding $($PicturePath) to $($UserAccount)"
    $pictureBinary = [byte[]](Get-Content $PicturePath -Encoding byte)
    If ([System.Text.Encoding]::ASCII.GetString($pictureBinary).Length -ge 100Kb) {
        Throw "Picture to large, max size is 100Kb"
    Try {
        Set-AdUser $UserAccount -Replace @{ thumbnailPhoto = $pictureBinary }
    Catch {
        Throw $error[0]

# one liner
Add-AdThumbnailPhoto -PicturePath "C:\MyPicture.jpg" -UserAccount "MyUserAccount"
# or
Set-AdUser "MyUserAccount" -Replace @{ thumbnailPhoto = ([byte[]](Get-Content "C:\MyPicture.jpg" -Encoding byte) }

Spiceworks Link



    [string] $ZipFilesPath = "X:\Somepath\Full\Of\Zipfiles",
    [string] $UnzipPath = "X:\Somepath\to\extract\to"
$Shell = New-Object -com Shell.Application
$Location = $Shell.NameSpace($UnzipPath)
$ZipFiles = Get-Childitem $ZipFilesPath -Recurse -Include *.ZIP
$progress = 1
foreach ($ZipFile in $ZipFiles) {
    Write-Progress -Activity "Unzipping to $($UnzipPath)" -PercentComplete (($progress / ($ZipFiles.Count + 1)) * 100) -CurrentOperation $ZipFile.FullName -Status "File $($Progress) of $($ZipFiles.Count)"
    $ZipFolder = $Shell.NameSpace($ZipFile.fullname)
    $Location.Copyhere($ZipFolder.items(), 1040) # 1040 - No msgboxes to the user - http://msdn.microsoft.com/en-us/library/bb787866%28VS.85%29.aspx

Spiceworks Link

PowerShell - Install Quest Tools



A Powershell script in the Printers category

Function Migrate-Printer {
    PARAM (
        [string] $ShareName,
        [string] $oldServer,
        [string] $newServer
    $currentPrinter = Get-WmiObject -Query "SELECT * FROM Win32_Printer WHERE Network=True AND ShareName = '$($ShareName)' AND SystemName = '\\\\$($oldServer)'"
    if ($currentPrinter -eq $null) {
        Write-Verbose "Cant find \\$($oldServer)\$($ShareName)"
    } else {
        Write-Verbose "Migrating printer $($ShareName) from $($oldServer) to $($newServer)"
        $net = New-Object -com WScript.Network
        Write-Verbose "Adding printer \\$($newServer)\$($ShareName)"
        Write-Verbose "Removing printer \\$($newServer)\$($ShareName)"
        if ($currentPrinter.Default -eq "True") {
            Write-Verbose "Setting default to \\$($newServer)\$($ShareName)"



A Powershell script in the Accounts and Passwords category

Function Get-RandomPassword {
    PARAM (
        $pwdMask = "####-####-####-####-####",
        $pwdCharacters = "abcdefghjkmnopqrstuvwxy23456789ABCDEFGHJKLMNPQRTUVWXYZ"
    $newPassword = ""
    (0 .. (($pwdMask.Length)-1) ) | ForEach-Object  {
        If ( $pwdMask.Chars($_) -eq "#" ) {
            $rndChar = Get-Random -Minimum 0 -Maximum $pwdCharacters.Length
            $newPassword += $pwdCharacters.Chars($rndChar)
        } else {
            $newPassword += $pwdMask.Chars($_)
    Return $newPassword
Function Set-LocalAdminPassword {
    PARAM (
        [string] $computerName,
        [string] $newPassword
    $adminAccountName = (Get-WmiObject Win32_UserAccount -Filter "LocalAccount = True AND SID LIKE 'S-1-5-21-%-500'" -ComputerName $computerName | Select-Object -First 1 ).Name
    TRY {
        Write-Verbose "Reset password for $($computerName)\$($adminAccountName) to $($newPassword)"
        $adminAccount = [adsi]"WinNT://$($computerName)/$($adminAccountName),user"
        Return $true
    CATCH {
        Return $false

Set-LocalAdminPassword -computerName "SOMEPC" -newPassword (Get-RandomPassword)


Powershell - Create a Password Protected encrypted drive

Create a Password Protected encrypted drive

using BitLockerPowershell module cmdlets.
When  I run the Get-BitLockerVolume cmdlet, it shows me the below output, you can see , that I have two drives are both are not encrypted.
I am interested in encrypting my Data Drive which is drive letter D:\.
Let's encrypt it.

To encrypt a drive, we use the Enable-BitLockerVolume cmdlet
Remember: We need to create a Secure String Password, if you want to open the BitLocker encrypted drive using Password.
$pass = ConvertTo-SecureString "Passw0rd" -AsPlainText -Force
In above command, we are creating a new secure string of text, Passw0rd, this will be out password to unlock the BitLocker encrypted drive.
Enable-BitLocker -MountPoint D:\ -EncryptionMethod Aes128 -Password$pass -PasswordProtector

PowerShell - Find running schedule tasks

Find running schedule

Get-Scheduledtask , type and run it and you will see list of you all cmdlets and if you want know about the running schedule tasks

Get-Scheduledtask  | where state -eq "Running"

PowerShell - Zip em Up

By using the Compress-Archive cmdlet.  The syntax of Compress-Archivecmdlet is simple, provide the -Path of the folder which you want to compress, then provide the      -DestinationPath of your .zip file and then set a -CompressionLevel, and after that hit enter.

Compress-Archive -CompressionLevel Optimal -Path C:\temp\Data\

-DestinationPath C:\temp\Compress.zip