thanks to everyone I did get it working see below. Still need to fix try-catch block but it creates a new ad users
$buttonSubmit_Click={
#TODO: Place custom script here
$remoteUsername = “cosdepot\dsfadmin”
$remotePassword = “lab@US24″
$Pass = ConvertTo-SecureString $remotePassword -asPlainText -force
$cred = new-object System.Management.Automation.PSCredential($remoteUserName, $pass)
$activeD = “labdc4″
$remoteFE= “lablync”
$remoteSP = “labsp”
$remoteUsername = “cosdepot\dsfadmin”
$remotePassword = “lab@US24″
$Pass = ConvertTo-SecureString $remotePassword -asPlainText -force
$cred = new-object System.Management.Automation.PSCredential($remoteUserName, $pass)
Write-Host “name” $Nametextbox1.Text
Write-Host “sam” $SamAccounttextbox2.Text
$Name = $Nametextbox1.Text
$SamAccount = $SamAccounttextbox2.Text
try
{
invoke-command -cn labdc4 -ScriptBlock { param ($Name, $SamAccount) new-aduser -name $Name -SamAccountname $SamAccount `
-path ‘cn=users, dc=cosdepot,dc=local’ -enabled $true -accountpassword (convertto-secureString -asplaintext “ZAQ!2wsx” -force)} -ArgumentList $Name, $SamAccount
}
catch {
}
}