Migrating Active Directory Users HomeDirectory to a new location

Migrating user home directories can be a tedious and time-consuming task for IT administrators. In this blog post, we will provide a PowerShell script that automates the process of copying user home directories from one location to another, while also updating the home directory path in Active Directory.

The script uses the robocopy command, which is a built-in command in Windows, to copy the home directories. Robocopy is a powerful tool that can copy files and folders, including permissions. This is important when migrating home directories as it ensures that the permissions for the users remain intact in the new location.

The script starts by importing the Active Directory module, which allows it to interact with Active Directory. Next, it defines the source and destination directories. In this example, the destination directory is "\\MyServer\NewHomeDirectories".

It then retrieves a list of all active users from Active Directory using the Get-ADUser command. The script loops through each user, retrieves their home directory path, and constructs the new home directory path using the user's SamAccountName.

Finally, the script uses robocopy to copy the home directory to the new location, including the permissions using the /E and /COPYALL options. It then updates the home directory path in Active Directory using the Set-ADUser command.

It is important to note that you need to have the appropriate permissions to read and copy the home directories and make changes in Active Directory. Additionally, it is recommended to test this script in a test environment before running it in a production environment.

Here is the script for your reference:

# Import the Active Directory module
Import-Module ActiveDirectory

# Define the new destination directory
$dstDir = "\\MyServer\NewHomeDirectories"

# Get all active users from Active Directory
$users = Get-ADUser -Filter {Enabled -eq $True}

# Loop through each user
foreach ($user in $users) {
    # Get the home directory path for the user
    $homeDir = $user.HomeDirectory

    # Construct the new home directory path
    $newHomeDir = $dstDir + "\" + $user.SamAccountName

    # Copy the home directory to the new location, including permissions
    robocopy $homeDir $newHomeDir /E /COPYALL

    # Update the home directory path in Active Directory
    Set-ADUser -Identity $user.DistinguishedName -HomeDirectory $newHomeDir
}

This PowerShell script can save IT administrators a lot of time and effort when migrating user home directories. By automating the process of copying home directories, including permissions, and updating the home directory path in Active Directory, this script can help ensure a smooth and successful migration.

Move Active Directory User-Profile to a new location

The script that I provided is designed to copy user profiles from Active Directory and move them to a new location. It uses the command line tool robocopy and also copies the permissions and ProfilePath property in Active Directory. This script is useful for organizations that want to move their user profiles to a new file server or storage location. It also includes the functionality to only select active users and rename the old path after copying it. It is important to note that this script should be used with caution, as it may have an impact on user data. It is recommended to take a backup of the Active Directory and the data before running the script. It is also good practice to test this script on a small subset of users before running it on the entire user population.

Please keep in mind that this is a script that should be used with caution and it's always recommended to test it and make a backup before running it in a production environment.

$newShare = "\\server\newshare\" # replace with the actual path of the new share
$users = (Get-ADUser -Filter {Enabled -eq $True} -Properties ProfilePath)
foreach ($user in $users) {
    if ($user.ProfilePath) {
        $oldPath = $user.ProfilePath
        $newPath = $newShare + $user.SamAccountName
        # copy the files to the new share with robocopy
        robocopy $oldPath $newPath /E /COPY:DAT /Z /SEC
        # update the ProfilePath property in AD
        Set-ADUser -Identity $user.SamAccountName -ProfilePath $newPath
        # rename the old profilepath
        Rename-Item -Path $oldPath -NewName ($oldPath + ".m2a")
    }
}


Azure VS On-Premise - Vorteile für mittelständische Unternehmen

Mittelständische Unternehmen stehen oft vor der Herausforderung, ihre IT-Infrastruktur zu modernisieren, ohne dabei ihre Finanzen zu belasten. Eine Möglichkeit, dies zu erreichen, ist die Migration der IT-Systeme in die Cloud. Einer der führenden Anbieter für Cloud-Computing ist Microsoft Azure. In diesem Artikel werden die Vorteile von Azure gegenüber einem On-Premise-Rechenzentrum für mittelständische Unternehmen erläutert.

1. Kosteneinsparungen: Ein großer Vorteil von Azure gegenüber einem On-Premise-Rechenzentrum ist die Kosteneinsparung. Mit Azure müssen Unternehmen keine teuren Hardware- und Softwarelizenzen erwerben oder Wartungskosten für ihre IT-Infrastruktur aufbringen. Stattdessen zahlen sie nur für die Ressourcen, die sie tatsächlich nutzen.

2. Flexibilität: Azure bietet Unternehmen die Möglichkeit, ihre IT-Ressourcen jederzeit zu skalieren. Wenn die Nachfrage steigt, können Unternehmen ihre Ressourcen problemlos erhöhen, ohne dass sie zusätzliche Hardware kaufen müssen. Auch wenn die Nachfrage sinkt, können Unternehmen ihre Ressourcen reduzieren, um Kosten zu sparen.

3. Hochverfügbarkeit: Azure bietet Unternehmen eine hohe Verfügbarkeit ihrer IT-Systeme durch die Nutzung von mehreren Rechenzentren. Dies gewährleistet, dass die IT-Systeme des Unternehmens auch bei Ausfällen oder Wartungsarbeiten weiterhin verfügbar sind.

4. Sicherheit: Azure bietet Unternehmen eine hohe Sicherheit ihrer Daten durch die Nutzung von verschiedenen Sicherheitsmaßnahmen wie Verschlüsselung und Zugriffssteuerung. Unternehmen haben damit auch die Möglichkeit, ihre Daten und Anwendungen in der Cloud zu speichern und zu verwalten, was vor allem für Remote-Arbeitsplätze von Vorteil ist.

5. Innovation: Azure bietet Unternehmen Zugang zu einer Vielzahl von innovativen Technologien wie künstlicher Intelligenz und maschinellem Lernen. Dies ermöglicht es Unternehmen, ihre Geschäftsprozesse zu optimieieren und neue Geschäftsmodelle zu entwickeln. Unternehmen haben damit die Möglichkeit, ihre Wettbewerbsfähigkeit zu steigern und schneller auf die sich verändernden Anforderungen des Marktes zu reagieren.

6. Umfangreiche Dienste und Anwendungen: Azure bietet Unternehmen eine breite Palette an Diensten und Anwendungen, die von der Speicherung und Verarbeitung von Daten über die Entwicklung von Anwendungen bis hin zur Bereitstellung von Virtualisierungstechnologien reichen. Dies ermöglicht es Unternehmen, ihre IT-Infrastruktur auf eine einheitliche Plattform zu migrieren und damit die Verwaltung und Wartung ihrer IT-Systeme zu vereinfachen.

7. Globaler Zugriff: Azure ermöglicht es Unternehmen, ihre IT-Systeme und Daten von überall auf der Welt aus zugreifen und nutzen zu können. Dies ermöglicht es Unternehmen, ihre Geschäftsprozesse und Anwendungen auch in anderen Regionen und Ländern bereitzustellen und damit ihre Präsenz auf dem globalen Markt zu erhöhen.

Insgesamt bietet Azure mittelständischen Unternehmen viele Vorteile gegenüber einem On-Premise-Rechenzentrum. Durch die Nutzung von Azure können Unternehmen ihre IT-Infrastruktur modernisieren, Kosten sparen, ihre Geschäftsprozesse optimieren und schneller auf die sich verändernden Anforderungen des Marktes reagieren. Daher ist eine Migration nach Azure für viele mittelständische Unternehmen eine attraktive Option, um ihre Wettbewerbsfähigkeit zu steigern und ihre Geschäftsprozesse zu optimieren.

Xamarin.iOS: Calculate distance between locations

Some people ask how using distance calculation in Xamarin iOS. Well, this is more simple than in Forms. Look at the code, but keep in mind to put a "using Corelocation" in the using section.

        public static double CalculateDistance(CLLocation location1, CLLocation location2)
        {
            double distance = location2.DistanceFrom(location1);

            return distance;
        }

        public static double CalculateDistance(params CLLocation[] locations)
        {
            double totalDistance = 0.0;

            for (int i = 0; i < locations.Length - 1; i++)
            {
                CLLocation current = locations[i];
                CLLocation next = locations[i + 1];

                totalDistance += CalculateDistance(current, next);
            }

            return totalDistance;
        }

Xamarin.Forms : Calculate distance between locations

Today I will show you, how simple distance calculation with Xamarin.Forms works. All you need are 2 GPS coordinates, called Location in Xamarin.Forms. The first class calculates the distance between two locations. The second one calculates the total distance between a list of locations. 

        private static double DegreesToRadians(double degrees)
        {
            return degrees * Math.PI / 180.0;
        }
        public static double CalculateDistance(Location location1, Location location2)
        {
            double circumference = 40000.0; // Earth's circumference at the equator in km
            double distance = 0.0;
 
            //Calculate radians
            double latitude1Rad = DegreesToRadians(location1.Latitude);
            double longitude1Rad = DegreesToRadians(location1.Longitude);
            double latititude2Rad = DegreesToRadians(location2.Latitude);
            double longitude2Rad = DegreesToRadians(location2.Longitude);
 
            double logitudeDiff = Math.Abs(longitude1Rad - longitude2Rad);
 
            if (logitudeDiff > Math.PI)
            {
                logitudeDiff = 2.0 * Math.PI - logitudeDiff;
            }
 
            double angleCalculation =
                Math.Acos(
                    Math.Sin(latititude2Rad) * Math.Sin(latitude1Rad) +
                    Math.Cos(latititude2Rad) * Math.Cos(latitude1Rad) * Math.Cos(logitudeDiff));
 
            distance = circumference * angleCalculation / (2.0 * Math.PI);
 
            return distance;
        }
 
        public static double CalculateDistance(params Location[] locations)
        {
            double totalDistance = 0.0;
 
            for (int i = 0; i < locations.Length - 1; i++)
            {
                Location current = locations[i];
                Location next = locations[i + 1];
 
                totalDistance += CalculateDistance(current, next);
            }
 
            return totalDistance;
        }

IIS : How to...redirect http-calls to https

If you use the Microsoft Information Server IIS 7 or above for your website, it is sometimes  necessary to redirect all incoming http traffic to secure url https. There are a lot of solutions doing this, i.e. build an index.html with redirect code to https-URL. But an other (maybe better) way is to rewrite the incoming URL with the "URL Rewrite" module in IIS. Well, you can use the graphical UI in Internet Information Services (IIS) Manager. But, this is not really simple to understand what you have to enter in the different fields. And.....this UI just writes the created rule to your web.config file. So, you can modify your web.config file with a text editor directly. 

In section <system.webServer> create a new section <rewrite> and enter the code below......or...."Copy&Paste". ;) After you have created this rule with an text editor, you can use the IIS GUI to review the rule and maybe you will see, why the text editor, was the better choice. ;)

 <system.webServer>
    <defaultDocument>
      <files>
        <clear />
        <add value="default.aspx" />
        <add value="Default.htm" />
        <add value="Default.asp" />
        <add value="index.htm" />
        <add value="index.html" />
        <add value="iisstart.htm" />
      </files>
    </defaultDocument>
        <handlers>
            <add name="PageHandlerFactory-ISAPI_4.0_64Bit" path="*.aspx" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
        </handlers>
        <rewrite>
            <rules>
                <clear />
                <rule name="Redirect to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
  </system.webServer>
This is how the resulting rule looks like in IIS-GUI after you created the rule in web.config

This is how the resulting rule looks like in IIS-GUI after you created the rule in web.config

Using an iPhone to control a Siemens S7 PLC

With this tool you can connect to a Siemens S7 Programmable Logic Controller (PLC), to read data blocks (DB) and/or structures (SZL). The driver is based on the free S7.NET  but got a lot of modifications for use with Xamarin on Android, iOS and tvOS. My formerly works are based on the PLCCom  driver, which have completly different calls. So I have to make a lot of modifications on the S7.NET driver to use my application code from older projects with the new driver. For security reasons the tool allows only read actions at the moment, but write data is implemented as well.

 

Fahrt im historischen Zug Schluff....

....von St. Tönis nach Krefeld-Hülser Berg. Klicke HIER für weitere Informationen.