Push domain accounts to Managed Accounts in SharePoint 2013

Tags: SharePoint 2013, Managed Accounts

#How to push a bunch of users as Managed Accounts in SharePoint 2013
CLS
Get-ADUser -SearchBase “ou=oua1,ou=oua,dc=example,dc=com” -Filter * -Properties * | 
    Where-Object {$_.SamAccountName -like 'sps*'} |
    Sort-Object -Property SamAccountName | 
    Select-Object SamAccountName, Name, UserPrincipalName  | %{
        
        [System.Security.SecureString] $strPass = $null
        $strPass = ConvertTo-SecureString -String "Pa`$`$w0rd" -AsPlainText -Force

        [object] $objCred = $null
        $objCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ("DOMAIN\$($_.SamAccountName)", $strPass)

        Get-Credential $objCred | New-SPManagedAccount -ErrorAction SilentlyContinue
    }