• Powershell

    Simple Powershell script to email locked out accounts to the admin

    1. Save the following into a file e.g lockedout.ps1 Import-Module ActiveDirectory -ErrorAction SilentlyContinue $Result = Get-ADUser ((Search-ADAccount -LockedOut).SamAccountName) | Select SamAccountName,Surname,GivenName,DistinguishedName | ConvertTo-Html | Out-String If ($Result) { Send-MailMessage -To email@me.com.au -From admin@somewhere.net.au -Subject "Currently Locked Out Accounts" -Body $Result -BodyAsHtml -SmtpServer mail.somewhere.net.au } 2. Setup up a task schedule to start at 12.00 AM and repeat every 15 minutes for the duration of 1 day. Use this as the command: Program/script: “powershell.exe” Arguments: -noprofile -executionpolicy unrestricted -file “C:\scripts\lockedout.ps1” You will now get emails when accounts get locked out. E.g SamAccountName   Surname Given Name   DistinguishedName abcuser   Joe Bloggs   CN=Joe Bloggs, OU=Staff Accounts, DC=company.local    

  • Powershell

    Remotely rename a PC with Powershell

    Do you need a quick and easy way to rename a computer that is joined to a domain remotely via Powershell? 1. Enable "Windows Management Instrumentation" and "Remote Management" rules on your computers firewall. This can be done via Group Policy for multiple computers. Note: If you don't enable WMI rules, you may get an error such as "Cannot establish WMI connection to computer. RPC server is not available." 2. Open cmd as an administrator and type powershell 3. Rename-computer –computername “testpc” –newname “newtestpc” -localcredential domain\user –domaincredential domain\user –force -passthru –restart This command renames the testpc computer to newtestpc and then restarts it to make the change effective. It uses:…

  • Powershell

    Need an easy way to move reserved IPs in DHCP?

    What does this script do? Okay, let’s say you have IPs in the DHCP reservation which you want to move to a new IP address then this Powershell script is for you. If you do it manually you will need to delete the reservation and create a new reservation with the mac address and new IP address. This script only requires the old IP address and the new IP. Make sure you update the DHCP server name. Here it is: Write-host '------------------------' Write-host '-- DHCP IP Mover --' Write-host '------------------------' #IP to Change #$ipaddress = '’ #New IP #$newip = '’ $ipaddress = Read-Host -Prompt 'Old IP: ' $newip =…