I was discussing with Oliver Wirkus how to use the SharePoint Client Side Object Model (CSOM) via PowerShell. We also wanted to read some configuration values from an XML file.

As CP pointed out, it is possible to get rid of the dynamic c#, which definetly Looks more elegant:

function GetWeb([string]$url)
{
    $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url);
    [Microsoft.SharePoint.Client.Web]$web = $clientContext.Web;
    $clientContext.Load($web);
    $clientContext.ExecuteQuery();
    return $web;
}

# Used to Load the SharePoint Client DLLs from the current directory
Add-Type -Path Microsoft.SharePoint.Client.dll
Add-Type -Path Microsoft.SharePoint.Client.Runtime.dll

#Read XML File and iterate all <user> Nodes
[Xml]$ConfigFile = Get-Content CSOMConfig.xml 
foreach( $user in $ConfigFile.Users.User) 
{ 
    # use XML Node "Name"
    $WebUrl="http://SOMEURL/" + $user.Name;
    # call GetWeb-method defined in CSOM code from above
    [Microsoft.SharePoint.Client.Web]$web = GetWeb($WebUrl);
} 

the corresponding CSOMConfig.xml file:

<users> 
  <user> 
    <name>SomeName</name> 
  </user> 
  <user> 
    <name>AnotherName</name> 
  </user> 
</users>

Just for completeness. All files are located on Folder:
CSOM_PowerShell_XML
You can also implement this solution with dynamic c# in PowerShell:
PowerShell:

$Assem = ( 
    "Microsoft.SharePoint.Client, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c", 
    "Microsoft.SharePoint.Client.Runtime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c",
    "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
$cSharp = @"
    using System;
    using System.Collections.Generic;
    using Microsoft.SharePoint.Client;
    
    namespace Enterprisebugs
    {
        public class SharePointList
        {
            public static Web GetWeb(string url)
            {
                var clientContext = new ClientContext(url);

                Web web = clientContext.Web;
                clientContext.Load(web);
                clientContext.ExecuteQuery();

                return web;
            }
        }
    }
"@

# Used to Load the SharePoint Client DLLs from the current directory
Add-Type -Path Microsoft.SharePoint.Client.dll
Add-Type -Path Microsoft.SharePoint.Client.Runtime.dll

# The CSOM code from above
Add-Type -ReferencedAssemblies $Assem -TypeDefinition $cSharp -Language CSharp;

#Read XML File and iterate all <user> Nodes
[Xml]$ConfigFile = Get-Content CSOMConfig.xml 
foreach( $user in $ConfigFile.Users.User) 
{ 
    # use XML Node "Name"
    $WebUrl="http://SOMEURL/" + $user.Name;
    # call GetWeb-method defined in CSOM code from above
    [Microsoft.SharePoint.Client.Web]$web = [Enterprisebugs.SharePointList]::GetWeb($WebUrl);
} 

Cool solution to use the CSOM via PowerShell! Thanks to Oliver as well 😉