Showing posts with label Filter. Show all posts
Showing posts with label Filter. Show all posts

Monday, August 1, 2016

Find member of based on job title

Here one I have no clue why I wrote it, in any event I thought I would share.  This script looks up all users with similar titles and documents every group they are a member of.  In environments where access is granted by a person’s job role this may come in handy to validate like job roles are in the same group, have the same access especially after adds/changes.

Start of script

Get-ADUser -filter { title -like "*Manager*" } | Select-Object samAccountName | foreach { (Get-ADUser $_.samAccountname –Properties MemberOf | Select-Object MemberOf).MemberOf | Out-File c:\temp\Member_of_Manager.txt }


End of script

Monday, July 25, 2016

Find all accounts that have their password set to never expire

This guy was written to address accounts that are in violation of policy.  Password set to never expire is an easy dig on an audit for auditors.  I run this every 90 days and investigate where needed.  Once the investigation is complete and all exceptions are approved any object leftover gets its password set to (PasswordNeverExpires -eq $False).

Get-ADUser -filter { Enabled -eq $True -and PasswordNeverExpires -eq $True } –Properties * |Select-Object Name, SAMAccountName, Title, Enabled, WhenCreated, WhenChanged, PasswordNeverExpires, Description | Export-Csv 'C:\temp\Pass_Never_Expires.csv' -NoTypeInformation –NoClobber


You can always run this as a scheduled task and email it to yourself.  That info can be found here: http://mytechnicalsolution.blogspot.com/search/label/send-MailMessage

Sunday, July 3, 2016

Document all Windows Server in the Domain

At my last job my CIO would always call me asking “what does server x do?” when change control voting was taking place.  This was mostly because our naming convention in no way resembled what the purpose of each server was.  So I decided to create a CSV weekly via scheduled task that documented the name of each server, its OS, and IP.  But most importantly it pulled in the description field from the computer object.  I know some of you will have to go back through your server objects and add a description but this was well worth the time and it made my CIO feel like I did this to make their job easier.

I used the Get-ADComputer but I had to make sure I only pulled out server OS.  So, I had to add a filter based off of the OperatingSystem field. Example: {OperatingSystem -Like "Windows *Server*"}  So if you wanted to find all Windows XP machines, just change the filter. Example: {OperatingSystem -Like "Windows *XP*"}  But alternatively if you want to find all machines expect Windows XP just change the filter to {OperatingSystem -NotLike "Windows *XP*"}

Start of script

Get-ADComputer -Filter {OperatingSystem -Like "Windows *Server*"} -Property * | Select-Object -Property Name,Description,OperatingSystem,OperatingSystemServicePack,IPv4Address | Export-Csv '\\your share\Server_Inventory.csv' -NoTypeInformation -Encoding UTF8

End of script


You can also use the Send-MailMessage command to email the csv as an attachment.  The command can be found here: http://mytechnicalsolution.blogspot.com/search/label/send-MailMessage