---
title: "PowerShell Functions vs. Cmdlets: Difference?"
description: "Learn the key differences between PowerShell commands, functions, and cmdlets. Understand when to use each one and how to inspect their code and functionality."
canonical: "https://adamtheautomator.com/powershell-commands-vs-cmdlets/"
---

# PowerShell Functions vs. Cmdlets: Difference?

> Learn the key differences between PowerShell commands, functions, and cmdlets. Understand when to use each one and how to inspect their code and functionality.

Source: https://adamtheautomator.com/powershell-commands-vs-cmdlets/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![PowerShell Functions vs. Cmdlets: Difference?](https://adamtheautomator.com/wp-content/uploads/2024/11/image-25.png)

# PowerShell Functions vs. Cmdlets: Difference?

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)7 November 20241 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Whenever you execute or run anything in PowerShell, you’re running a “command.” A command is an informal term for executable code, which can be a built-in PowerShell cmdlet, a custom function, or even an object method.

Cmdlets are compiled executable code provided by Microsoft, created in a language like C#, compiled, and added to a PowerShell module by software developers. Functions, on the other hand, are created directly in PowerShell by users. Although functions and cmdlets are technically different, they can be thought of as similar when you’re starting out.

To demonstrate functions vs. cmdlets, let’s dig in with a short demo. Let’s find all of the available commands in the current session:

```
## Find all of the available command types
Get-Command | Group-Object -Property CommandType
```

![](https://adamtheautomator.com/wp-content/uploads/2024/11/2024-11-03_13-33-59-1024x188.png)

_**People often interchange the terms commands, cmdlets, and functions. If this becomes confusing, remember that a “command” generally refers to either a cmdlet or a function.**_

The `Group-Object` cmdlet groups properties, and here it provides a summary of commands by type.

You’ll see command types like aliases, cmdlets, and functions. Let’s inspect the code behind one of the cmdlets:

```
Get-Command -Name Get-Content | select -ExpandProperty Definition
```

![](https://adamtheautomator.com/wp-content/uploads/2024/11/image-35-1024x293.png)

The `Definition` property contains the code for a function, and parameter sets for a cmdlet. In the case of cmdlets, you’ll only see parameter sets.

_**While cmdlets are more optimized for performance due to their precompiled nature, functions offer flexibility. For tasks involving custom logic or data processing, functions allow you to go beyond what cmdlets can do, providing room for creativity and problem-solving.**_

Now, let’s inspect a function:

```
Get-Command -Name Add-BitLockerKeyProtector | select -ExpandProperty Definition
```

![](https://adamtheautomator.com/wp-content/uploads/2024/11/image-36-1024x296.png)

You can see the actual PowerShell code for functions.

If you wish to see the module that a function resides in, you can look at the `Source` property:

```
Get-Command -Name Add-AzADAppPermission
```

![](https://adamtheautomator.com/wp-content/uploads/2024/11/2024-11-03_13-35-50-1024x115.png)

To locate the module, use:

```
Get-Module -Name BitLocker | select Path
```

![](https://adamtheautomator.com/wp-content/uploads/2024/11/2024-11-03_13-36-14-1024x131.png)

This command will show the module’s path. For example, if the module is located in `/Users/adam/.local/share/powershell/Modules/Az.Resources/7.4.0/Az.Resources.psm1`, you can open it in VS Code for further inspection.

```
code '/Users/adam/.local/share/powershell/Modules/Az.Resources/7.4.0/Az.Resources.psm1'
```

Inside the module, you’ll find several functions written in PowerShell, which you can explore and modify as needed.

It’s important to remember that although cmdlets tend to perform better, especially with large datasets, functions can be more versatile. They allow for the creation of custom workflows and logic that aren’t possible with cmdlets alone.

When deciding between using a cmdlet or a function, think about the task at hand. Cmdlets are ideal for built-in tasks that are already optimized, but if you need more control or customization, functions are your best bet. Functions can help create reusable code blocks, streamline complex tasks, and enhance overall script modularity.

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-commands-vs-cmdlets%2F&text=PowerShell%20Functions%20vs.%20Cmdlets%3A%20Difference%3F)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-commands-vs-cmdlets%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-commands-vs-cmdlets%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b81e69730da4c690758c2/4afeea42b7f854d23285b281664351779f042510f1e3a1d766d02cfa39b711a8.jpg)

### [Find and Disable Every Inactive AD Computer with PowerShell](/find-inactive-computers-active-directory/)

Find inactive computer accounts in Active Directory with Search-ADAccount, then disable and quarantine them with PowerShell in steps you can undo.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b814eba23fbf8d18b64a2/ade916ad78256face2456a10aacfbb82051f4957bf03d6f163193b25395e5183.jpg)

### [Back Up and Restore Every Group Policy Object in PowerShell](/backup-restore-gpos-powershell/)

Back up every Group Policy Object with Backup-GPO, restore one or all with Restore-GPO, and recover a deleted GPO with Import-GPO and New-GPLink.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b8181be1be294c37c6724/0ba6a36aaba4a30390fca48d395a19d38846d030302d345372b68b077c3a5cdc.jpg)

### [Find Stuck DFS Replication Backlogs with PowerShell](/dfs-replication-backlog-powershell/)

Find out whether DFS Replication is caught up. Get-DfsrBacklog reads the full file count past the 100-file limit, then a loop checks every group.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
