# Powershell script to run amother domail

**URL:** <https://forums.powershell.org/t/powershell-script-to-run-amother-domail/9719>\
**Category:** PowerShell Help\
**Created:** [November 16, 2017, 12:53am UTC](https://forums.powershell.org/t/powershell-script-to-run-amother-domail/9719 "2017-11-16T00:53:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gauravkumar](https://avatars.discourse-cdn.com/v4/letter/g/e480ec/32.png) [@gauravkumar](https://forums.powershell.org/u/gauravkumar)\
**Post date:** [November 16, 2017, 12:53am UTC](https://forums.powershell.org/t/powershell-script-to-run-amother-domail/9719/1 "2017-11-16T00:53:33Z")

</div>

Hi guys,

I am using this script ($password = ConvertTo-SecureString “passwordofmachine” -AsPlainText -Force  
$cred= New-Object System.Management.Automation.PSCredential (“domainname”, $password )  
Invoke-Command -ComputerName computername -ScriptBlock { Get-ChildItem “F:” -Recurse | Move-Item -Destination “E:” } -credential $cred ) to enter in my VM and run this script. But am getting an error that this Vm is registered on another domain. can anyone tell me how can i access my VM registered on another domain by my local machine. if anyone know than please tell me.

Thanx and regards  
Gaurav Kumar

---

<div class="post-metadata">

**Author:** ![alex-aymonier](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@alex-aymonier](https://forums.powershell.org/u/alex-aymonier)\
**Post date:** [November 16, 2017, 10:31pm UTC](https://forums.powershell.org/t/powershell-script-to-run-amother-domail/9719/2 "2017-11-16T22:31:36Z")

</div>

Try this and see how you go 1st then change the ScriptBlock

```
$password = ConvertTo-SecureString "passwordofmachine" -AsPlainText -Force

$cred= New-Object System.Management.Automation.PSCredential ("domainname\Username", $password )

Invoke-Command -ComputerName "computername.domainname" -ScriptBlock { test-path -Path "f:" } -credential $cred
```

---

<div class="post-metadata">

**Author:** ![gauravkumar](https://avatars.discourse-cdn.com/v4/letter/g/e480ec/32.png) [@gauravkumar](https://forums.powershell.org/u/gauravkumar)\
**Post date:** [November 16, 2017, 11:34pm UTC](https://forums.powershell.org/t/powershell-script-to-run-amother-domail/9719/3 "2017-11-16T23:34:00Z")

</div>

i had tried this code but this code occurs the same error.

---

<div class="post-metadata">

**Author:** ![sanchez](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sanchez](https://forums.powershell.org/u/sanchez)\
**Post date:** [November 17, 2017, 7:42am UTC](https://forums.powershell.org/t/powershell-script-to-run-amother-domail/9719/4 "2017-11-17T07:42:49Z")

</div>

Have you tried by IP address instead of DNS name? I am thinking there might be an issue with how the domains are structured, but can’t be for sure without any details on the domain setup.

---

<div class="post-metadata">

**Author:** ![pradeeparoratx](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@pradeeparoratx](https://forums.powershell.org/u/pradeeparoratx)\
**Post date:** [November 17, 2017, 12:36pm UTC](https://forums.powershell.org/t/powershell-script-to-run-amother-domail/9719/5 "2017-11-17T12:36:40Z")

</div>

I see you used

```
PSCredential (“domainname”, $password )
```
  
instead of suggested 
```
PSCredential (“domainname\Username”, $password )
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:37pm UTC](https://forums.powershell.org/t/powershell-script-to-run-amother-domail/9719/6 "2024-05-16T20:37:12Z")

</div>


