Test-ComputerSecureChannel

Test and repair the secure channel between the local computer and its domain.

Syntax
      Test-ComputerSecureChannel [-Repair] [-Credential PSCredential] [-Server string]
         [-Confirm] [-WhatIf] [CommonParameters]

Key
   -Repair
       Remove and then rebuild the secure channel established by the
       NetLogon service. Use this parameter to try to restore a connection
       that has failed the test (returned "False".)

To use this parameter, the current user must be a member of the Administrators group on the local computer.
-Credential PSCredential Specifies a user account that has permission to perform this action. The default is the current user. Type a user name, such as User64 or SS64Dom\User64, or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, this cmdlet prompts you for a password. This parameter was introduced in PowerShell 3.0
-Server string Use the specified domain controller to run the command. If this parameter is omitted, Test-ComputerSecureChannel selects a default domain controller for the operation. -Confirm Prompt for confirmation before executing the command. -WhatIf Describe what would happen if you executed the command without actually executing it.

Test-ComputerSecureChannel verifies that the secure channel between the local computer and its domain is working correctly by checking the status of its trust relationships. If a connection fails, use the -Repair parameter to try to restore it.

Test-ComputerSecureChannel returns "True" if the secure channel is working correctly and "False" if it is not. This result lets you use the cmdlet in conditional statements in functions and scripts. To get more detailed test results, use the -Verbose parameter.

This cmdlet works much like NetDom.exe. Both NetDom and Test-ComputerSecureChannel use the NetLogon service to perform the actions.

Examples

Test the secure channel between the local computer and the domain to which it is joined:

PS C:> test-computersecurechannel

Prompt for credentials and perform a repair of the secure channel:

PS C:> Test-ComputerSecureChannel -Repair -Verbose -Credential (Get-Credential)

Use Test-ComputerSecureChannel to test a connection before running a script that requires the connection:

PS C:> if (!(test-computersecurechannel))
     {write-host "Connection failed. Reconnect and retry."}
else { &(.\collectserverdata.ps1) }

Use Invoke-Command to run a Reset-ComputerMachinePassword command on the Server64 remote computer.

PS C:> invoke-command -computername Server64 -scriptblock {reset-computermachinepassword}

“Life is thickly sown with thorns, and I know no other remedy than to pass quickly through them. The longer we dwell on our misfortunes, the greater is their power to harm us” ~ Voltaire

Related PowerShell Cmdlets

Restart-Computer - Restart the operating system on a computer.
Test-Connection - Ping one or more computers.


 
Copyright © 1999-2024 SS64.com
Some rights reserved