AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-06-28 · Documentation low

File: code-library/latest/ug/iam_example_iam_DeleteUser_section.md

Summary

Added comprehensive PowerShell V5 user deletion example with dependency cleanup

Security assessment

Provides complete user deletion workflow including credential cleanup, which is critical for access revocation but doesn't indicate a security flaw fix

Diff

diff --git a/code-library/latest/ug/iam_example_iam_DeleteUser_section.md b/code-library/latest/ug/iam_example_iam_DeleteUser_section.md
index 37af53192..ce9fd30a2 100644
--- a//code-library/latest/ug/iam_example_iam_DeleteUser_section.md
+++ b//code-library/latest/ug/iam_example_iam_DeleteUser_section.md
@@ -510,0 +511,54 @@ PowerShell
+**Tools for PowerShell V5**
+    
+
+**Example 1: This example deletes the IAM user named`Bob`.**
+    
+    
+    Remove-IAMUser -UserName Bob
+    
+
+**Example 2: This example deletes the IAM user named`Theresa` along with any elements that must be deleted first.**
+    
+    
+    $name = "Theresa"
+    
+    # find any groups and remove user from them
+    $groups = Get-IAMGroupForUser -UserName $name
+    foreach ($group in $groups) { Remove-IAMUserFromGroup -GroupName $group.GroupName -UserName $name -Force }
+    
+    # find any inline policies and delete them
+    $inlinepols = Get-IAMUserPolicies -UserName $name
+    foreach ($pol in $inlinepols) { Remove-IAMUserPolicy -PolicyName $pol -UserName $name -Force}
+    
+    # find any managed polices and detach them
+    $managedpols = Get-IAMAttachedUserPolicies -UserName $name
+    foreach ($pol in $managedpols) { Unregister-IAMUserPolicy -PolicyArn $pol.PolicyArn -UserName $name }
+    
+    # find any signing certificates and delete them
+    $certs = Get-IAMSigningCertificate -UserName $name
+    foreach ($cert in $certs) { Remove-IAMSigningCertificate -CertificateId $cert.CertificateId -UserName $name -Force }
+    
+    # find any access keys and delete them
+    $keys = Get-IAMAccessKey -UserName $name
+    foreach ($key in $keys) { Remove-IAMAccessKey -AccessKeyId $key.AccessKeyId -UserName $name -Force }
+    
+    # delete the user's login profile, if one exists - note: need to use try/catch to suppress not found error
+    try { $prof = Get-IAMLoginProfile -UserName $name -ea 0 } catch { out-null }
+    if ($prof) { Remove-IAMLoginProfile -UserName $name -Force }
+    
+    # find any MFA device, detach it, and if virtual, delete it.
+    $mfa = Get-IAMMFADevice -UserName $name
+    if ($mfa) { 
+        Disable-IAMMFADevice -SerialNumber $mfa.SerialNumber -UserName $name 
+        if ($mfa.SerialNumber -like "arn:*") { Remove-IAMVirtualMFADevice -SerialNumber $mfa.SerialNumber }
+    }
+    
+    # finally, remove the user
+    Remove-IAMUser -UserName $name -Force
+    
+
+  * For API details, see [DeleteUser](https://docs.aws.amazon.com/powershell/v5/reference) in _AWS Tools for PowerShell Cmdlet Reference (V5)_. 
+
+
+
+