How to join and unjoin a domain using poweshell in vb.net

Mostafa Salaheldien 61 Reputation points
2021-04-08T21:23:57.617+00:00

Hello everyone,
I would like to join a domain using vb.net I want to insert this line in PowerShell after I launch it
I am using this code

' Process.Start("Powershell", "add-computer -domainname xxx -credential AD\xxx -restart -force" )

it's working for me but not asking to enter the username and the password for the domain

I found another code

    Process.Start("powershell", "$domain = "MYDOMAIN.COM" + _

"$password = Read-Host -Prompt "Enter password For $user" -AsSecureString" + _
"$credential = New-Object System.Management.Automation.PSCredential($username,$password)" + _
"Add-Computer - DomainName $domain -Credential $credential"")

but it's not working at all
thanks in advanced
anonymous user
@Kareninstructor

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,778 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.