C# - Get All Active Directory Users in a Group

Use the following handy method to get all users in an AD group .NET 3.5 Add a reference to System.DirectoryServices.AccountManagement public static List<UserPrincipal> GetAllUsersInGroup(string domain, string groupname) { List<UserPrincipal> result = new List<UserPrincipal>(); using (var context = new PrincipalContext(ContextType.Domain, domain)) using (var group = GroupPrincipal.FindByIdentity(context, groupname)) { if (group != null) { result.AddRange(group.GetMembers(true).Cast<UserPrincipal>().ToList()); } } return result; } private static string GetADStatus(int inputField) { // Assume the user is disabled string result = "Disabled"; // Declare the hex for the accountDisabled flag int accountDisabled = 0x00000002; // https://msdn. [Read more...]

Windows - Robocopy File Mirrors and Backups

Using the /MIR switch Copy all files, replacing files in the destination or deleting files in the destination that are not in the source folder. Copy without any permissions. robocopy "\\MySource\Folder" "\\MyDestination\Folder" /MIR /r:1 /w:1 /copy:DAT /xf *.pst Thumbs.db /np /tee /log:c:\roboCopy.log /MIR Mirrors a directory tree (equivalent to /e plus /purge). The /mir option is equivalent to the /e plus /purge options with one small difference in behavior: With the /e plus /purge options, if the destination directory exists, the destination directory security settings are not overwritten. [Read more...]

C# - Read a .csv in .NET

// Namespace: Microsoft.VisualBasic.FileIO // https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser%28v=vs.110%29.aspx // Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll) private static List<SourceDocument> ReadCSV(string p) { List<SourceDocument> docs = new List<SourceDocument>(); using (TextFieldParser parser = new TextFieldParser(p)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { //Processing row string[] fields = parser.ReadFields(); if (fields[0].Trim().ToUpper() != "HEADER1NAME") { SourceDocument doc = new SourceDocument(); doc.StringField = fields[0].Trim(); doc.IntField = Convert.ToInt32(fields[1]); doc.DateField = Convert.ToDateTime(fields[2]); docs.Add(doc); } } } return docs; }

C# - Task Patterns

Tasks Get The Number of Logical Cores var logicalCoreCount = Environment.ProcessorCount; Wait All One By One List < Task <TResult>> tasks = new List < Task<TResult>> (); for (int i = 0; i < N; i++) // Start N tasks: { tasks.Add( Task.Factory.StartNew<TResult> (code) ); } while (tasks.Count > 0) { // Get the array index of the task that finishes first int index = Task.WaitAny( tasks.ToArray() ); // This will never throw an exception here // Catch the exception like this try { tasks[index]. [Read more...]

Windows - Changing a network interface profile to Private

Isn’t Windows Easy? Changing a network interface profile to Private Windows interfaces kind of suck. Let’s change one from whatever Windows decided to allocate it to and make it into a Private interface. First, let’s take a look at all of the interfaces on the machine. netsh interface ip show interfaces This is great, but the PowerShell commands we are going to use will only alllow us to change active connections. [Read more...]

Linux - Cant Ping Ubuntu Vm by Name From Windows Machine

In order to ping an Ubuntu box using its NetBIOS name, use the following steps: edit /etc/nsswitch.conf Replace this line: hosts: files dns With this line: hosts: files dns wins Next, install winbind: sudo apt-get install winbind. Now the machine should be ready to ping from Windows.

Ubiquiti - Getting Rid of the CenturyLink Router

Getting Rid of the CenturyLink Router When CenturyLink (CL) installed Fiber-To-The-Home (FTTH) with Prism service, they also required the use of their router/modem. I learned to hate this junky device with wi-fi issues and intermittent connection problems. Luckily, the modem of this device was not used. The modem was locked up in the access box outside. Looking at the back of the Technicolor C2000T, the WAN port was connected by a regular Cat 5e cable, indicating that there was no need for the purchase of a fiber-modem. [Read more...]

Ubiquiti - Configuring an EdgeRouter X to Replace a CenturyLink Router

Previously, I discussed various options when considering the replacement of a CenturyLink Technicolor C2000T router/modem in Getting Rid of the CenturyLink Router. Time to get rid of the CenturyLink router. With the Ubiquiti EdgeRouter X plugged in, and the eth1 port hooked up to my laptop’s LAN port, getting to the login was easy enough. In the Windows Network and Sharing Center, I selected the ethernet adapter’s properties and gave it a static IP of 192. [Read more...]

C# - Enumerating a Registry Key Results in a Null Value

This post assumes .NET 4.0 After trying for some time to get a registry key to list all of its subkeys, I kept getting a null value back. This code does not work It always returns null. var keyName = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileGuid"; using (var guidSet = Registry.LocalMachine.OpenSubKey(keyName)) { if (guidSet != null) { foreach (var guid in guidSet.GetSubKeyNames()) { result.Add(guid); Console.WriteLine("{0}", guid); } } } This code works var keyName = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileGuid"; using (var hklm = RegistryKey. [Read more...]

Bootstrap - Adding a Bootstrap Datepicker With the Eternicode Package to an MVC Project

Manage Nuget Packages Search for and install the Eternicode Bootstrap Datepicker https://github.com/eternicode/bootstrap-datepicker In the BundleConfig.cshtml bundles.Add(new ScriptBundle("~/bundles/bootstrap-datepicker").Include( "~/Scripts/bootstrap-datepicker.js")); //added for bootstrap datepicker bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/bootstrap.css", "~/Content/site.css", "~/Content/datepicker.css" //added for bootstrap datepicker )); In the shared view _Layout.cshtml make the following changes to the head section @*Scripts moved up to the head section so that they render before the body*@ @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/jqueryval") @*for jquery validation*@ @Scripts.Render("~/bundles/bootstrap") @Scripts.Render("~/bundles/bootstrap-datepicker") @*for bootstrap datepicker*@ @*Script section for bootstrap datepicker*@ <script> var datepicker = $. [Read more...]