I need a powershell command to get when an active directory user got disabled, any help please??
Take a look at this site:
Or check for events with ID 4725 on your Security event logs (if AD audit is enabled)
This is a very common task, and a quick search using your post title would show you many results and samples to use.
This specifically what the *eventlog* cmdlets are for.
Get-Command -Name '*eventlog*' | Format-Table -AutoSize
CommandType Name Version Source----------- ---- ------- ------Cmdlet Clear-EventLog 126.96.36.199 Microsoft.PowerShell.ManagementCmdlet Get-EventLog 188.8.131.52 Microsoft.PowerShell.ManagementCmdlet Limit-EventLog 184.108.40.206 Microsoft.PowerShell.ManagementCmdlet New-EventLog 220.127.116.11 Microsoft.PowerShell.ManagementCmdlet New-PefEventLogTrigger 18.104.22.168 PEFCmdlet Remove-EventLog 22.214.171.124 Microsoft.PowerShell.ManagementCmdlet Show-EventLog 126.96.36.199 Microsoft.PowerShell.ManagementCmdlet Write-EventLog 188.8.131.52 Microsoft.PowerShell.Management
Here is part of a large snippet I give out when deliver PS classes, internally and externally. Make this a snippet in the ISE or VSCode or whatever editor you use, so you can pop it up as needed. Keeping all your target help resources in a concise location, ensures you have a consistant starting point.# Get parameters, examples, full and Online help for a cmdlet or function
# Get a list of all functionsGet-Command -CommandType Function | Out-GridView -PassThru -Title 'Available functions'
# Get a list of all commandletsGet-Command -CommandType Cmdlet | Out-GridView -PassThru -Title 'Available cmdlets'
# Get a list of all functions for the specified nameGet-Command -Name '*eventlog*' -CommandType Function | Out-GridView -PassThru -Title 'Available named functions'
# Get a list of all commandlets for the specified nameGet-Command -Name '*eventlog**' -CommandType Cmdlet | Out-GridView -PassThru -Title 'Available named cmdlet'
# get function / cmdlet details(Get-Command -Name Get-EventLog).ParametersGet-help -Name Get-EventLog -ExamplesGet-help -Name Get-EventLog -FullGet-help -Name Get-EventLog -Online
This translates into you are very new to PowerShell. So, the recommendation is that you spend the time ramping up on it to limit the amount of confusion, frustrations, misconceptions and mistakes you will encounter.
See these resources.
PowerShell Standard Library: Build single module that works across Windows PowerShell and PowerShell Corehttps://blogs.msdn.microsoft.com/powershell/2018/08/06/powershell-standard-library-build-single-module-that-works-across-windows-powershell-and-powershell-core
Windows PowerShell Best Practiceshttps://www.microsoftpressstore.com/store/windows-powershell-best-practices-9780735666498
PowerShell scripting best practiceshttps://martin77s.wordpress.com/2014/06/17/powershell-scripting-best-practiceshttps://blogs.technet.microsoft.com/heyscriptingguy/tag/best-practices
Powershell - Recommended coding stylehttps://lazywinadmin.com/2011/06/powershell-recommended-coding-style.html
What is the recommended coding style for PowerShell?https://stackoverflow.com/questions/2025989/what-is-the-recommended-coding-style-for-powershell
PowerShell 4.0 Best Practices scriptsThis is a place holder for all the scripts from my forthcoming Windows PowerShell 4.0 Best Practices book. Once the book releases, I will upload the 200 scripts to this location -- which is currently referenced in my book. The idea is similiar to the one that I did for the Wihttps://gallery.technet.microsoft.com/scriptcenter/PowerShell-40-Best-d9e16039
Using tools that write code for you or provide sonnets for you to start from
• Scriptomatic2.exe• ScriptomaticV2.hta• ScriptomaticV2.2.hta• EZADScriptomatic.exe• PowerShellScriptOMatic v.1.0• PowerShellScriptOMaticSetup.msi• ADAC - PowerShell History Viewer (already mentioned above)
The ADSI Scriptomatic is designed to help you write ADSI scripts; that is, scripts that can be used to manage Active Directory.https://www.microsoft.com/en-us/download/details.aspx?id=20460
Scriptomatic 2.2 - with search functionScriptomatic 2 is very useful for generating WMI scripts, but there are bugs in its date converter function. I have updated it with a new function.https://gallery.technet.microsoft.com/scriptcenter/Scriptomatic-21-aka-shame-9cdc28b5
Take Advantage of Scriptomatic 2.0 to Maximize Your WMI Scripting Effortshttps://www.itprotoday.com/devops-and-software-development/take-advantage-scriptomatic-20-maximize-your-wmi-scripting-efforts
Two Minute Drill: Scriptomatic 2.0https://blogs.technet.microsoft.com/askperf/2009/02/17/two-minute-drill-scriptomatic-2-0
Take advantage of all the samples / examples in the toolsA Favorite PowerShell ISE Feature: Snippetshttps://blogs.technet.microsoft.com/heyscriptingguy/2016/01/07/a-favorite-powershell-ise-feature-snippets
VbsEdit, the award-winning VBScript editor that dramatically reduces the time you spend writing .VBS scriptshttps://www.vbsedit.com
Creating PowerShell ISE v3 (and later) Code Snippetshttps://www.jonathanmedd.net/2013/11/creating-powershell-ise-v3-and-later-code-snippets.html
Weekend Scripter: The WMI Explorer Toolhttps://blogs.technet.microsoft.com/heyscriptingguy/2014/09/13/weekend-scripter-the-wmi-explorer-tool
Coretech WMI and PowerShell Browser – CTGlobalhttps://blog.ctglobalservices.com/powershell/kaj/coretech-wmi-and-powershell-browser
Snippet Manager 4.01 releasedhttps://bytecookie.wordpress.com/2015/09/19/snippet-manager-4-01-released
PowerShell Code Manager 6https://bytecookie.wordpress.com/powershell-code-manager
SnippetManager & Injector 3 / Code Snippet Manager for ISE, PowerGUI andhttps://gallery.technet.microsoft.com/scriptcenter/SnippetManager-Injector-3-89eaf7a7
Step-By-Step: Utilizing PowerShell History Viewer in Windows Server 2012 R2https://blogs.technet.microsoft.com/canitpro/2015/03/04/step-by-step-utilizing-powershell-history-viewer-in-windows-server-2012-r2
Learning PowerShell with Active Directory Administrative Center (PowerShell History Viewer)https://sid-500.com/2017/10/10/learning-powershell-with-active-directory-administrative-center-powershell-history-viewer
Powered by IDERA