Skip to content

Instantly share code, notes, and snippets.

@mdehaas
Last active June 7, 2021 09:28
Show Gist options
  • Save mdehaas/f88a2a0a4ce34d09cc7126cd1b967ade to your computer and use it in GitHub Desktop.
Save mdehaas/f88a2a0a4ce34d09cc7126cd1b967ade to your computer and use it in GitHub Desktop.
Powershell script to disable Windows Surface internal Hello camera when an external IR camera is present. I'm using this on a Surface Laptop. Use the XML to import a scheduled task (RunAs should be an Admin on the device).
## Script Specific configuration
$ExternalCameraFriendlyName = "RGB-IR Camera"
## Generic configuration
$Verbose = $true
$Debug = $false
$WhatIf = $false
### END CONFIGURATION #####
$basePath = $MyInvocation.MyCommand.Path.Replace($MyInvocation.MyCommand.Name,"").SubString(0,($MyInvocation.MyCommand.Path.Replace($MyInvocation.MyCommand.Name,"").length-1))
$baseName = $MyInvocation.MyCommand.Name.Remove(($MyInvocation.MyCommand.Name.Length-4),4)
$Transcript = !$WhatIf
if ($Transcript) {Start-Transcript -Path "$($basePath)\$($baseName)-$($env:USERNAME).transcript.log" -Append -Verbose:$Verbose}
if (($CurrentStateExt = Get-PnpDevice -Verbose:$Verbose| Where {$_.FriendlyName -like "RGB-IR Camera" -and $_.Manufacturer -notlike "Microsoft"}).Present -notlike 'True') {
Write-Verbose "External Windows Hello Camera is unavailable." -Verbose:$Verbose
switch ((Get-PnpDevice -Verbose:$Verbose | Where {$_.FriendlyName -like "Microsoft IR Camera Front"}).Problem) {
"CM_PROB_DISABLED" {Write-Verbose "Enabling the internal Windows Hello Camera." -Verbose:$Verbose
Get-PnpDevice -Verbose:$Verbose| Where {$_.FriendlyName -like "Microsoft IR Camera Front"} | Enable-PnpDevice -Verbose:$Verbose -Confirm:$false -WhatIf:$WhatIf
}
"CM_PROB_PHANTOM" {}
"CM_PROB_NONE" {Write-Verbose "The internal Windows Hello Camera is already enabled." -Verbose:$Verbose}
}
} else {
Write-Verbose "External Windows Hello Camera is available." -Verbose:$Verbose
switch ((Get-PnpDevice -Verbose:$Verbose | Where {$_.FriendlyName -like "RGB-IR Camera" -and $_.Manufacturer -like "Microsoft"}).Problem) {
"CM_PROB_DISABLED" {Write-Verbose "The internal Windows Hello Camera is already disabled." -Verbose:$Verbose}
"CM_PROB_PHANTOM" {}
"CM_PROB_NONE" {Write-Verbose "Disabling the internal Windows Hello Camera." -Verbose:$Verbose
Get-PnpDevice -Verbose:$Verbose | Where {$_.FriendlyName -like "Microsoft IR Camera Front"} | Disable-PnpDevice -Verbose:$Verbose -Confirm:$false -WhatIf:$WhatIf
}
}
}
if ($Transcript) {Stop-Transcript}
break
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2018-05-25T09:32:30.4538883</Date>
<Author>Windows Hello Camera Switcher</Author>
<URI>\Windows Hello Camera Switcher</URI>
</RegistrationInfo>
<Triggers>
<TimeTrigger>
<Repetition>
<Interval>PT1M</Interval>
<StopAtDurationEnd>false</StopAtDurationEnd>
</Repetition>
<StartBoundary>2018-05-25T09:31:31</StartBoundary>
<Enabled>true</Enabled>
</TimeTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId></UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>powershell</Command>
<Arguments>-File "C:\Scripts\Windows Hello Camera Switcher\Windows Hello Camera Switcher.ps1" -NoProfile -ExecutionPolicy Bypass</Arguments>
</Exec>
</Actions>
</Task>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment