Category: Windows

  • Remove duplicates, blank lines, spaces, to get unique values and sort data in one operation

    Remove duplicates, blank lines, spaces, to get unique values and sort data in one operation

    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 applies to numbers.

    Software Prerequisites:

    • NotePad++
    • TextFX Characters Plug-in for NotePad++

    Enabling TextFX Characters Plug-in

    Install NotePad++ with all defaults

    Goto Plugins > Plugin Manager > Show Plugin Manager

    Install TextFX Characters Plugin

    Once successfully downloaded it will prompt for a restart.

    After a successful restart of the application you should now see the TextFX entry in the toolbar.

    Removing duplicates, blank lines, and sorting data

    • Paste the text into Notepad++ (CTRL+V). As you can see, there were lines and half of them were blank.

    • Mark all the text (CTRL+A). Click TextFX → Click TextFX Tools → Check +Sort outputs only UNIQUE (at column) lines (if not already checked).

    • Click TextFX → Click TextFX Tools → Click Sort lines case insensitive (at column)

    • Duplicates and blank lines have been removed and the data has been sorted alphabetically. (The first line that may appear empty contains a space, which is regarded as a character and is included in the list of unique data.)

    [su_tooltip position=”north” content=”Please check permissions on the files and folders. If you have unique or specialized permission on the file or folders these wont work.”]

    Changing to lowercase

    To change the text to lowercase Goto: TextFX > TextFX Characters > lower case[/su_tooltip]

    This has saved me a lot of time when working with IP addresses or cleaning up text.

     

  • Delete Files and Folders Older Than X Days

    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.

    [su_tooltip position=”north” content=”Here’s what all of those funky switches do. The first two arguments are for the InstallShield application, setup.exe. /S requests a silent installer, and /v lets the application know that you’re going to pass switches directly to the MSI. This is why the command structure after the /v is enclosed in double quotes. The /qn portion is MSI-speak for no user interface, while the REBOOT=R portion is toReallySupress the reboot. ADDLOCAL is describing what features to install locally, while REMOVE states to toss out the HGFS (Shared Folders) feature. This way ensures that new features will be added without having to call them all out in a list.”]Please check permissions on the files and folders. If you have unique or specialized permission on the file or folders these wont work.[/su_tooltip]

    Batch File:

    @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:

    # 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:

    # 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
    	}
    }

    Hope this helps!

  • 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 free.

    Here is what my UserList.csv look like:

    sAMAccountName,Password
    test1,gqLfZub$OtO#dBg
    test2,6eXq78gTyx$YjmM
    test3,ZNgl!KdYo7U6yzR
    test4,voiIs!TISw!Wcyc
    test5,W7ZBTAe7CWcFzyn
    test6,BykgCY5b*NGFO5!
    test7,3ApLlchwgRQwf1P
    test8,9jZvvR2$wDggf3M
    test9,*QCDjcgnNLkBDP1
    test10,sZpvUnvjJxAE9HE
    test11,$C8TX!tcS3d#MjK
    test12,Pzw*aH6zjpOx8Wj
    test13,XmfIPiIz82!!X77
    test14,ri!!hQX!w!FSZuI
    test15,S0Gzf6fEUsG!4Ib
    test16,Kj8s!vy94S!ozLJ
    test17,PzFzjP7obALeuWa
    test18,Ri5V2laxxck6Rgg
    test19,Rw8KcX*FoMT#gr1
    test20,QDndAgzdYo5CYX!

    Make sure you do the following on a domain controller or connecting to your domain controller via PS-remote with elevated permissions.

    Run this in PowerShell (Open PowerShell in Admin Mode)

    PowerShell:

    Import-Module Active Directory
    $Resetpassword = Import-Csv "c:\_Scripts\UserList.csv"
    
    foreach ($Account in $Resetpassword) {
        $Account.sAMAccountName
        $Account.Password
            Set-ADAccountPassword -Identity $Account.sAMAccountName -NewPassword (ConvertTo-SecureString $Account.Password -AsPlainText -force) -Reset
    }

    [su_note note_color=”#fafae8″]-Reset
    Specifies to reset the password on an account. (User is not prompted to change password).
    To use this parameter, you must set the -NewPassword parameter.
    You do not need to specify the -OldPassword parameter.
    [/su_note]

  • 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:

    error

    I have only tested this solution on:

    2016-10-04_11-41-47

    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 them. I didn’t have the patch.

     wusa.exe /uninstall /KB:3142024

    Hope this helps.

  • Windows: Hide Internet Explorer 11 address bar & navigation bar

    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 View Mode which by default will remove the TABS and Address bar via a GPO.

    The GPO  you can use to enforce the Full-Screen view is available on both Computer and User configuration policy. Below is the gpo location path in group policy editor console.

    • GPO NAME: Enforce full-screen mode
    • LOCATION: Computer or User configuration – Computer Configuration\Administrative Templates\Windows Components\Internet Explorer
    • KEY LOCATION: Software\Policies\Microsoft\Internet Explorer\Toolbars\Restrictions

    SCREENSHOT: GPO CONSOLE

    2352.GPO-LOCATION

    WINDOWS REGISTRY:

    This will cause the IE address bar to not show. I disabled the Navigation bars too so it gives a clean window experience.

    SCREENSHOT: REGISTRY LOCATION WITH VALUES

    1172.GPO-REGISTRY-LOCATION

    Download the Registry file.

    The GPO and keys will cause the browser to open in full view with no address bar or tabs

    7536.FULL-VIEW-AFTER-GPO

  • 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 need to do:

    If your e-mails are in A column, go in the B column and in the B1 cell and copy paste this code:

    =AND(FIND("@";B2);FIND(".";B2);ISERROR(FIND(" ";B2)))

    Then, go down and left on the B1 cell so you can copy and paste the code to the other cells.  For all the valid e-mails, it will give you ‘TRUE’ and for the invalid ‘FALSE’.

    2016-08-25_14-34-49

  • 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 the DFS Namespace service attempts to access Active Directory before it has completely initialized.
    To resolve this issue, we simply have to force the DFS Namespace service to start after the Active Directory service has initialized. We can do this by setting the DFS Namespace service to depend on the Active Directory service as well as setting it to a Delayed Startup mode.

    To make those changes, start regedit and make the following changes :

    1. Navigate to the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Dfs
    2. Modify the DependOnService value and add NTDS to the list.
    3. Create a new DWORD value named DelayedAutostart and set its value to 1.
  • 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:

    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:

    Get-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
    

    To disable proxy from PowerShell:

    Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 0

    To enable proxy from PowerShell:

    Set-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ProxyEnable -value 1