Monthly Archives: February 2014

Change the Network Location in Server 2012 R2

I needed to configure a Windows 2012 R2 server for some services to test, but didn’t want to domain join it.  By default, the network location was listed as public.
As such, firewall rules were not being followed.
To change the network location, open gpedit.msc (Local Group Policy Editor), and navigate to Computer Configuration / Windows Settings / Security Settings / Network List Manager Policies.
Double click the Network name of network that you would like to change the location.
Select the Network Location tab, and set the location to relevant setting.
Click OK, and close Local Group Policy Editor.  The network location has now changed to the location you set.

Delete Files Containing a Specific String Using Powershell

I had a number of files, and wanted to delete the files that contained a specific string.  Using Powershell, this can be completed using the following (one line):

get-childitem *.txt | select-string “%STRING_TO_DELETE%” | group path | select name | foreach-object {remove-item $_.name}

Where %STRING_TO_DELETE% is the string that will determine if the file is deleted. EG (one line):


get-childitem *.txt | select-string “SUCCESS” | group path | select name | foreach-object {remove-item $_.name}
 
This will delete any .TXT files in the current directory that contain the string SUCCESS
 
Specifically this was used to remove emails from the mail queue of an Exchange 2003 server that was spamming after a user account was compromised.  I noticed the spam all contained the string “I have urgent feasible plan aligned with our mutual economical interests”.  Using Powershell, I navigated to the mail queue directory, and used the following command:
 

get-childitem *.eml | select-string “I have urgent feasible plan aligned with our mutual economical interests” | group path | select name | foreach-object {remove-item $_.name}

This deleted all the .eml files with the spam string.