Forum Discussion
lfk73
Apr 13, 2021Copper Contributor
Switch to different domain
I am logging into a machine on a domain that is different to the domain I want to query. There is a trust between the two domains but when I run scripts its run against the domain I am logged into. How do I switch to the other domain that I want to run the script against?
3 Replies
Sort By
- farismalaebSteel ContributorWould you please tell us which script this is?
Depend. Usually, most of the cmdlets accept server parameter and credential parameters. Use these two parameters to connect to the remote server.
But keep in mind that authentication protocol is used.- lfk73Copper ContributorThey vary. I'm using small scripts found here and there to help me collect information. For example I found the below script that will give me a list of all accounts with password set to never expire.
Search-ADAccount -PasswordNeverExpires -UsersOnly -ResultPageSize 2000 -resultSetSize $null | Select-Object Name, SamAccountName, DistinguishedName | Export-CSV “C:\Temp\PassNeverExpiresUsers.CSV” -NoTypeInformation
I would also use a script (once I find or write it) that grabs all accounts and provides me their password settings like length, complexity, expiry time etc. looking for weak accounts. I just need to make sure when it runs it rungs against the right domain- farismalaebSteel ContributorThese are all related to ActiveDirectory Module, and this Module support a parameter named -Server
use the following:
$x=Get-Credential
Search-ADAccount -PasswordNeverExpires -UsersOnly -Server The_Remote_Server_FQDN -Credential $x
When you execute this, you will be prompt to type the username and password, type the remote server username and password and then... you got your result.
Just make sure that you have a connection to the remote server and the firewall is not blocking it.
Hope this help
---------------
If this answer helped, please click on best respone.