I'm trying to add a computer to SCCM, but not having much luck. This is for testing so I'm generating the MAC and ComputerName randomly. I keep getting the error 'Exception calling "InvokeMethod" with "3" argument(s): "Generic failure ". Can someone tell me what I'm doing wrong? I know I'm getting a good connection to the SCCM server because I can run a SelectQuery to get information from SCCM. I also know it's not a permissions issue, as I have been successful using another method to add a computer using this same account.
FYI, I'm avoiding using "[wmiclass]" type constructors because I will be translating this to vb.net later for incorporation into a project in Visual Studio and didn't know how to translate "[wmiclass]" into vb.net, whereas objects created via New-Object should be easy.
Here is my code:
$MAC = '{0:X12}' -f (Get-Random 0xFFFFFFFFFFFF) | ? {$_ -match ('(..)' * 6)} | % { $Matches[1..6] -join ':' }
$ComputerName = 'w-amtest-l-{0:D5}' -f (Get-Random 99999)
Write-Host ('Adding {0} (MAC {1}) to SCCM' -f $ComputerName,$MAC)
$SCCMServerName = 'enaarwmg02'
$SiteName = 'site_AM2'
$CollectionName = 'AM20002F'
#endregion
#region Initialize connection to the SCCM 2012 Environment
$ScopeOptions = $Null
$Scope = New-Object System.Management.ManagementScope -ArgumentList "\\$SCCMServerName\root\sms\$SiteName",$ScopeOptions
$Null = $Scope.Connect()
$Site = New-Object System.Management.ManagementClass -ArgumentList $Scope,'SMS_Site',$Null
#endregion
#region Add the computer to SCCM
$MethodName = 'ImportMachineEntry'
$InParams = $Site.GetMethodParameters($MethodName)
$InParams.MACAddress = $MAC
$InParams.NetbiosName = $ComputerName
$InParams.OverwriteExistingRecord = $false
$CMComputer = $Site.InvokeMethod($MethodName, $InParams, $Null)
Any help would be appreciated.

