Skip to content

Instantly share code, notes, and snippets.

@steviecoaster
Created November 16, 2018 18:27
Show Gist options
  • Save steviecoaster/9763661a1bfae924e253a265b5b468ca to your computer and use it in GitHub Desktop.
Save steviecoaster/9763661a1bfae924e253a265b5b468ca to your computer and use it in GitHub Desktop.
Get a toast on Windows 10 when a workstation finishes encrypting with Bitlocker
Function Get-BitlockerEncryptionToast {
[cmdletBinding()]
Param(
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string]
$Computername
)
Start-Job -ScriptBlock {
If ($using:Computername) {
$Session = New-PSSession -ComputerName $using:Computername
}
Function Get-Percentage {
If ($using:Computername) {
$script:EncryptionPercentage = Invoke-Command -Session $Session -ScriptBlock { (Get-BitLockerVolume).EncryptionPercentage }
}
Else {
$script:EncryptionPercentage = (Get-BitLockerVolume).EncryptionPercentage
}
}
#Get the value currently, before dropping into the while loop.
Get-Percentage
#Sleep for 5 minutes between checks, as encryption does take some time to complete
While ($EncryptionPercentage -lt 100) {
Start-Sleep -Seconds (60 * 5)
Get-Percentage
}
$Header = New-BTHeader -Id 1 -Title "Encryption Complete!"
New-BurntToastNotification -Text "Encryption on $($using:Computername) has completed!" -Header $Header -Silent
Get-PSSession | Remove-PSSession
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment