\n Hi, and welcome to the PowerShell forum! \n\n\nDon’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask! \n\n\nUse a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which. \n\n\nDon’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…\n <\/blockquote>\n<\/aside>\n\n <\/p>","upvoteCount":1,"datePublished":"2021-04-22T17:17:56.000Z","url":"https://community.spiceworks.com/t/powershell-to-delete-specific-user-certificates/797764/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Hello Neally, \nAppreciate the correction, in my rush to get closure on this hurdle of mine, I posted it without thinking. The post has been edited appropriately, by chance do you have an answer to this question?<\/p>","upvoteCount":0,"datePublished":"2021-04-22T17:39:33.000Z","url":"https://community.spiceworks.com/t/powershell-to-delete-specific-user-certificates/797764/3","author":{"@type":"Person","name":"spiceuser-a5t7l","url":"https://community.spiceworks.com/u/spiceuser-a5t7l"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-a5t7l:<\/div>\n
\nHello Neally, \nAppreciate the correction, in my rush to get closure on this hurdle of mine, I posted it without thinking. The post has been edited appropriately, by chance do you have an answer to this question?<\/p>\n<\/blockquote>\n<\/aside>\n
Welcome. this is a free and volunteer based forum so there is no ‘immediate’ answer unless someone, well, provides one, so you have to be patient.<\/p>\n
how about like so<\/p>\n
$users = \"Cert1\" , \"Cert2\" , \"Cert3\"\nforeach($cert in (Get-ChildItem Cert:\\CurrentUser\\My)){\n if($cert.Subject -notmatch \"$($users -join \"|\")\"){\n remove-item \"Cert:\\CurrentUser\\My\\$($cert.thumbprint)\" -verbose \n }\n}\n\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2021-04-22T17:53:01.000Z","url":"https://community.spiceworks.com/t/powershell-to-delete-specific-user-certificates/797764/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Hello again Sir, \nFirst off, thank you, sincerely you really nailed it. I just need to wrap it into a nice batch file for my shop and my H/R users to employ. I previously was utilizing this line of code:<\/p>\n
powershell.exe -Command \"Get-ChildItem Cert:\\CurrentUser\\My | Remove-Item\"\n<\/code><\/pre>\nwhich essentially nuked all the certificates, in a neat batch file. Utilizing your code, I replace “Get-ChildItem Cert:\\CurrentUser\\My | Remove-Item” with your code, however it did not go as I had thought it did. I am more than likely going about this the wrong however uncertain as to what I need to do in order to remedy it. I know the first part of my batch opens PowerShell, the second part tells PowerShell to run the command within the quotation marks. Again, blindly stabbing in the dark, I believe there is a translation conflict between my batch file and the script you provided. Do you know how I can modify your great product to work in my batch file Sir?<\/p>","upvoteCount":0,"datePublished":"2021-04-23T12:03:22.000Z","url":"https://community.spiceworks.com/t/powershell-to-delete-specific-user-certificates/797764/5","author":{"@type":"Person","name":"spiceuser-a5t7l","url":"https://community.spiceworks.com/u/spiceuser-a5t7l"}},{"@type":"Answer","text":"
why batch file?<\/p>\n
just call the powershell script from batch, if you need to do that.<\/p>\n
Powershell.exe -executionpolicy bypass -File \"C:\\scripts\\remove-Certs.ps1\"\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2021-04-23T13:21:24.000Z","url":"https://community.spiceworks.com/t/powershell-to-delete-specific-user-certificates/797764/6","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Hello again Sir, \nHonestly the thought process behind going towards a singular batch file was ease of setup for either the deployment admin or individual end-user. Providing a step-by-step coloring book guide to those target audiences, as a fire and forget solution. I could even cater it to my customer base and pre-build their batch files for them by inputting into the command line their respective digital certificates, emailing it to them, and simply instructing them to save the file to X folder locale, then copy a shortcut to their desktops, double-click when needed, rinse and repeat. I was able to meet the intended end-state however, in that once setup, the end-user can delete all other user’s digital certificates from their store. Long story short, my H/R folks, as well as subordinate desktop support techs acquire a lot of digital signatures overtime for their respective customers. Using these actions, which again I cannot thank you enough, they can now expunge them without going through the eight or nine step process to clear those certificates manually. While I am aware there are faster methods, various GPOs prevent standard users from accessing some of those resources, ergo this spurned my thought process to run down a singular batch file; that, and I cannot seem to make a .ps1 file type executable through double-clicking the file.<\/p>","upvoteCount":0,"datePublished":"2021-04-23T14:44:42.000Z","url":"https://community.spiceworks.com/t/powershell-to-delete-specific-user-certificates/797764/7","author":{"@type":"Person","name":"spiceuser-a5t7l","url":"https://community.spiceworks.com/u/spiceuser-a5t7l"}},{"@type":"Answer","text":"