How to Get AD User’s Group Membership

To Get User’s security group membership Run below command: Get-ADPrincipalGroupMembership -Identity user  | where {$_.groupCategory -eq ‘Security’} |  add-adgroupmember -members USER To get all groups that a user is a member of Run below command: Get-ADPrincipalGroupMembership username | select name Name —- Domain Users Domain Computers Workstation Admins Company Users Company Developers AutomatedProcessingTeam You may … Read more

How to Generate Random Password using PowerShell

Try the below powershell script to generate random password as per required characters and length. With the help of below scrip you can configure complex passwords to services or any account user. function Generate-Password { $alphabets= “abcdefghijklmnopqstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()” $char = for ($i = 0; $i -lt $alphabets.length; $i++) { $alphabets[$i] } for ($i = 1; $i … Read more

How to List Local Administrators Using PowerShell

Try the below script, in order to audit or list local administrators. Here is the VBScript Set objGroup = GetObject(“WinNT://./Administrators,group”) For Each objUser In objGroup.Members WScript.Echo “Member found: ” & objUser.Name Next set objGroup = Nothing Here is the Powershell syntax function LogToFile ([string]$strFileName, [string]$strComputer) { Add-Content $strFileName $strComputer } $strComputer = “.” $computer = … Read more

How to Export Windows Event Logs with PowerShell Script

The below script creates a .evt file which can be used with the Windows Event log Viewer. # Config $logFileName = “Application” # Add Name of the Logfile (System, Application, etc) $path = “C:\temp\” # Add Path, needs to end with a backsplash # do not edit $exportFileName = $logFileName + (get-date -f yyyyMMdd) + … Read more