PowerShell Script to Disable and Enable Webcam on Windows 10 and Windows 11
While using laptops, sometimes you may want to disable the built-in webcam for some reasons, such as security or debugging webcam related programs. Not like a USB webcam, the built-in camera is unpluggable. Therefore, a general way is to open the device manager, find the camera, and disable it. To save time, we can create PowerShell scripts to toggle camera status quickly.
What you’ll build: A PowerShell script pair that disables and re-enables any connected webcam on Windows 10/11 by querying PnP device IDs, plus .cmd batch file shortcuts that run with a double-click as administrator.
Key Takeaways
- PowerShell’s
Disable-PnpDeviceandEnable-PnpDevicecmdlets can toggle any USB or built-in webcam without opening Device Manager. - Filtering by
-Class Cameraprevents accidentally disabling audio input on combo peripherals like the Logitech C920. - Scripts work on Windows 10 and Windows 11 with PowerShell 5.1 and PowerShell 7.
- Batch file wrappers let you create desktop shortcuts to toggle webcam status with a double-click at administrator privilege.
Common Developer Questions
- How do I disable a webcam using PowerShell on Windows 10 or Windows 11?
- How do I find the InstanceId of a webcam device using PowerShell?
- How do I run a PowerShell
.ps1script as administrator from a.cmdbatch file?
Prerequisites
- Windows 10 or Windows 11
- Windows PowerShell 5.1 or PowerShell 7, running as administrator
- A connected webcam (built-in or USB)
Step 1: Disable and Enable Webcam on Windows 10/11 with PowerShell
List All Webcam Devices Using Get-PnpDevice
Run the Windows Powershell command-line tool as administrator.
We can use Get-PnpDevice cmdlet to enumerate all devices known to PnP (Plug and Play).
Since I just want to list webcam devices, I can filter the devices by name:
Get-PnpDevice -FriendlyName *webcam*

As you can see, I have two webcams: a built-in USB webcam and a Logitech C920 webcam.

The Logitech C920 webcam also supports audio input which should not be listed here. Therefore, I need to take a further step to filter the results by adding the class name:
Get-PnpDevice -FriendlyName *webcam* -Class Camera,image

The Logitech C920 webcam is physically removable, and thus my target is the built-in XiaoMi USB 2.0 Webcam.
Disable and Enable the Webcam by Instance ID
Use Disable-PnpDevice cmdlet to disable the built-in webcam by instance Id:
Disable-PnpDevice -InstanceId (Get-PnpDevice -FriendlyName *webcam* -Class Camera -Status OK).InstanceId
Once a device is disabled, its status will be changed to Error. To make the webcam work again, use Enable-PnpDevice cmdlet. Change the current status from OK to Error:
Enable-PnpDevice -InstanceId (Get-PnpDevice -FriendlyName *webcam* -Class Camera -Status Error).InstanceId
I can use the online webcam app to check the camera status as I execute the commands.
Create Batch File Shortcuts to Toggle Webcam Status
Finally, in order to quickly run the scripts, save the commands to disable.ps1 and enable.ps1 files.
By default, a *.ps1 file will be opened in Notepad when we double-click it. To run the script directly, I created two batch files and corresponding desktop shortcuts. We have to use an absolute path, not a relative path for finding the ps1 file.
// disable.cmd
powershell -file d:\disable.ps1
// enable.cmd
powershell -file d:\enable.ps1
Right-click a shortcut file and go to Properties > Advanced. Check “Run as administrator”.

Now I can double-click the batch files to toggle webcam status.

Common Issues & Edge Cases
- “No devices found” with
Get-PnpDevice -FriendlyName *webcam*: Some OEMs register built-in cameras under a different display name (e.g.,*camera*or the model name). RunGet-PnpDevice -Class Camerato list all Camera-class devices regardless of friendly name. - Interactive confirm prompt blocks the script: By default,
Disable-PnpDeviceandEnable-PnpDeviceask for confirmation. Add-Confirm:$falseto suppress the prompt when running non-interactively from a batch file. - Command fails after a Windows 11 feature update: Occasionally, Windows 11 updates can change how webcam classes are registered. If
-Class Camera,imagereturns empty results, fall back toGet-PnpDevice -Class Cameraalone, or query by-FriendlyNamewith the exact model string shown in Device Manager.
Source Code
https://gist.github.com/yushulx/27ecfc190ed091dc6373e43c6558e582