Join our Newsletter — 33% off our NHI Course
Foundations & NHI Taxonomy

Add-Type

← Back to Glossary
By NHI Mgmt Group Updated November 9, 2026 Domain: Foundations & NHI Taxonomy

Add-Type is a PowerShell cmdlet that compiles source code or loads a .NET type into a session. It is used to create custom classes, call unmanaged APIs, or add compiled assemblies, so it expands what a script can do at runtime.

What Add-Type Changes in a PowerShell Session

Add-Type is a runtime extension mechanism, not just a convenience wrapper. It lets a script bring in new .NET types or compile source code on the fly, which can make an automation task possible without rebuilding the whole application. That flexibility is powerful, but it also means the session can gain new behavior, new execution paths, and new dependencies at runtime.

Because the cmdlet changes what the current session can do, it sits at the boundary between scripting and code execution. In practice, that means the security posture of the script is no longer limited to the original PowerShell commands, it now includes whatever code is introduced, compiled, or loaded through the cmdlet.

Why Add-Type Matters for Security

From a security perspective, Add-Type expands the blast radius of a trusted script. If an attacker can influence the source code, assembly path, or surrounding script logic, they may be able to introduce unmanaged calls, custom classes, or additional runtime capability that the original author did not intend. That makes source integrity and script trust especially important.

The cmdlet is also relevant because it can bridge into lower-level APIs and compiled code. That does not make it inherently malicious, but it does mean reviewers should treat it as a higher-risk construct than ordinary variable or function usage. The main question is not whether Add-Type is allowed, but whether the added code is expected, reviewed, and necessary for the task at hand.

Common Uses and Operational Trade-offs

Developers and administrators use Add-Type for legitimate reasons: creating small helper types, calling platform APIs, or loading assemblies that provide functionality PowerShell does not natively expose. This can reduce dependency on external binaries or modules and can simplify a workflow when the code is tightly controlled.

The trade-off is that runtime compilation and type loading can reduce transparency. A script may appear simple on the surface while actually embedding significant logic inside a type definition or a compiled code block. That makes code review, logging, and change control more important, especially in administrative automation, build pipelines, or scripts that run with elevated privileges.

What Reviewers Should Look For

Security review should focus on where the type source comes from, whether it is static or dynamically constructed, and whether the script loads only the types it genuinely needs. Add-Type is not risky because it exists; it is risky when it hides behavior, widens execution authority, or introduces opaque code paths that are hard to inspect later.

A practical review also checks whether the script is compiling code on every run, importing unnecessary assemblies, or using the cmdlet as a workaround for a design problem that should be solved elsewhere. Those patterns can create maintainability issues as well as security blind spots.

Risk and Threat Considerations

Add-Type can become a code-injection or privilege-abuse vector when untrusted input influences the generated source, the loaded assembly, or the script that invokes it. The security concern is not the cmdlet itself, but the fact that it can turn a scripting surface into a code-loading surface with much less visibility than a normal compiled application.

Failure mechanism: An attacker or careless operator supplies malicious or altered source, and the session compiles or loads it with the permissions of the running process. That can introduce arbitrary behavior, enable unmanaged API calls, or create a persistence-friendly execution path inside administrative tooling.

Impact: The result can be command execution, expanded local privilege abuse, hidden functionality in automation, or harder-to-detect compromise of scripts that otherwise look benign. Review of script provenance, input handling, and loaded code becomes essential when this cmdlet is present.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST SP 800-53 Rev 5SC-18 — Mobile CodeAdd-Type introduces runtime-loaded code into a script session.
SI-7 — Software, Firmware, and Information IntegrityAdd-Type depends on trusting the integrity of the source and assemblies it loads.
SA-11 — Developer Testing and EvaluationScripts using Add-Type need review and validation of the embedded code path.
Recommendation — Restrict and review runtime code loading in scripts that compile or import types. Verify the integrity and provenance of code loaded through PowerShell scripts. Test and evaluate embedded code paths before allowing runtime compilation in production scripts.
CIS Controls v8CIS-10 — Malware DefensesRuntime code loading can introduce malicious code into administrative endpoints.
CIS-16 — Application Software SecurityAdd-Type affects the security of custom script logic and embedded code.
Recommendation — Scan and monitor scripts that compile or load code at runtime. Review custom PowerShell code paths for unsafe runtime compilation and loading.

Practitioner Guidance

Why practitioners should care: Use Add-Type only when runtime type creation or assembly loading is genuinely required, because it changes the trust boundary of the script. Code that compiles or loads additional types should be treated as part of the security-sensitive attack surface, not as a harmless scripting shortcut.

What to watch for: Pay close attention to dynamically built source strings, unexpected assembly paths, and scripts that rely on Add-Type to hide complex logic. Those patterns deserve the same level of scrutiny you would apply to any other code supply chain issue inside an automation workflow.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on November 9, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org