From time to time I come across this need; where I need to scrub a file where there are duplicates, there are blank lines, the sort order is all wack, and it just needs to be formatted to where it can be more readable and/or usable. This method just doesn’t apply to text, but also…
Category: Windows
Delete Files and Folders Older Than X Days
Often times admin have to creates tasks like removing log files or some other files on a regular schedule. Here is an automated way of removing files / folders older than X days. Create a Batch file or Powershell script and add it to scheduled task. Batch File:
1 2 3 4 5 6 7 8 9 10 11 12 |
@echo off :: set folder path set dump_path=c:\shares\dump :: set min age of files and folders to delete set max_days=7 :: remove files from %dump_path% forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd /c del /q @path" :: remove sub directories from %dump_path% forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path" |
Powershell:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# set folder path $dump_path = "C:\shares\dump" # set min age of files $max_days = "-7" # get the current date $curr_date = Get-Date # determine how far back we go based on current date $del_date = $curr_date.AddDays($max_days) # delete the files Get-ChildItem $dump_path -Recurse | Where-Object { $_.LastWriteTime -lt $del_date } | Remove-Item |
Remove disabled users from Distribution Lists & Security Groups in Active Directory
One of my clients had several disabled users showing up in distribution lists and security groups and this was creating unnecessary noise in email, alerts, etc. I highly encourage all administrators to keep their AD neat and tidy. The following PowerShell script searches for disabled users in Groups and Distribution Groups and removes them:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# This script removes all disabled users from all security and distribution groups in the specified "searchOU" Import-Module ActiveDirectory $searchOU = "OU=Groups,DC=domain,DC=local" $adgroup = Get-ADGroup -Filter 'GroupCategory -eq "Security" -or GroupCategory -eq "Distribution"' -SearchBase $searchOU $adgroup | ForEach-Object{ $group = $_ Get-ADGroupMember -Identity $group -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $false}} | ForEach-Object{ $user = $_ $uname = $user.Name $gname = $group.Name Write-Host "Removing $uname from $gname" -Foreground Yellow Remove-ADGroupMember -Identity $group -Member $user -Confirm:$false } } |
…
Active Directory: Changing passwords for users in bulk using a .csv file
Many accounts in your AD might need a password change. What if you want to do this in bulk ? First, we need to the userlist. Depending on your requirements we need to get a list of users (specifically samaccountname). For random password generation I recommend using http://manytools.org/network/password-generator/ as it can generate up 1000 for…
VMware: Intermittent Error: Unexpected character ‘’ (code 65279 / 0xfeff) in prolog; expected ‘<' at [row,col {unknown-source}]: [1,1] pop up in Windows vSphere client ?
Recently, I got the error below when using the vSphere client. Problem: I have only tested this solution on: Solution: Repair your installation of Microsoft Visual J#® 2.0 Redistributable Package – Second Edition (x64) Download The error went away after repair. In trying to google the error some user have reported that uninstall the patch KB3147458 worked for…
Windows: Hide Internet Explorer 11 address bar & navigation bar
Applies to: Windows Server 2008R2, Windows Server 2012R2, Windows 10 There are two ways this can be accomplished depending on your needs for the controlled environment. GPO: I would like to first clarify that there is not a single GPO to just hide TABS in IE11. There is however a way you can enforce IE in Full…
Excel: Check email addresses in bulk if format is correct or not
So had a request today to clean up email addresses as some of them were not valid. This was needed for over 1500 email addresses. So used the formula below and was able to find all addresses that were “FALSE”. I filtered them out and was able to fix them as needed. Here’s what you…
DFS Namespace service could not initialize cross forest trust information
After you install Active Directory on Windows Server 2008 R2, you may start seeing the following error message after the server boots: The DFS Namespace service could not initialize cross forest trust information on this domain controller, but it will periodically retry the operation. The return code is in the record data. This occurs because…
DNS broken after Windows Update KB3145126
I noticed the DNS broke on my servers after Windows Update. The problem was KB3145126. Read more about it here. After a quick removal and reboot, DNS was operational again. To remove/uninstall KB3145126, open powershell and run the following:
1 |
wusa.exe /uninstall /KB:3145126 |
Hope this helps.
Check Proxy settings from Powershell
To check the proxy settings like ProxyOveride or if it is enabled or not:
1 |
Get-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" |
To disable proxy from PowerShell:
1 |
Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 0 |
To enable proxy from PowerShell:
1 |
Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 1 |