Powershell script to run amother domail

Welcome Forums General PowerShell Q&A Powershell script to run amother domail

This topic contains 4 replies, has 4 voices, and was last updated by

 
Participant
1 year ago.

  • Author
    Posts
  • #84367

    Participant
    Points: 0
    Rank: Member

    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

  • #84439

    Participant
    Points: 70
    Rank: Member

    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
    
    
    • #84442

      Participant
      Points: 0
      Rank: Member

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

    • #84488

      Participant
      Points: 0
      Rank: Member

      I see you used

      PSCredential ("domainname", $password )

      instead of suggested

      PSCredential ("domainname\Username", $password )
  • #84461
    Jon

    Participant
    Points: 35
    Rank: Member

    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.

The topic ‘Powershell script to run amother domail’ is closed to new replies.