When scripting, sanity check logging takes way more time that actions. Before binding to an Active Directory domain, you should verify that your system isn’t currently a member of an Active Directory domain. After binding, you should also check that settings are as expected. Use the get-addomain commandlet to do so:
Get-ADDomain
To be more specific about a given domain:
PS C:\> Get-ADDomain -Identity krypted.com