none
Powershell: Mount network path on remote machine RRS feed

  • Question

  • Hi Team,

    I am using Powershell to trigger commands on remote machine. I am using below script to trigger commands.

    $ComputerName = "xxx.xxx.xxx.xxx"
    $CredentialsFile = "C:\Automation\creds.xml"

    Function ExecuteCommand() {

        $NetworkPath = "\\xxx.xxx.xxx.xxx\C$\mySharedPath"
        $Username = "xxx\user"
        $Password = "xxxxxx"

        net use Z: $NetworkPath /user:$Username $Password | Out-Null
    }

    Set-Item WSMan:\localhost\Client\Trustedhosts -Value $ComputerName -Concatenate -Force
    $Credentials = Import-Clixml $CredentialsFile
    Invoke-Command -ComputerName $ComputerName -Credential $Credentials -ScriptBlock ${function:ExecuteCommand} -HideComputerName

    The above script runs successfully and but the Mounted network path status is Unavailable. 

    And when I run Get-PSDrive command remotely using the same above script, it doesn't return network shared drive details.

    Can someone please help here?

    Powershell version: 4.0

    OS: Windows Server 2012 R2

    Thanks,

    Sachin

    • Moved by Bill_Stewart Thursday, December 13, 2018 3:17 PM This is not "scripts on demand"
    Tuesday, September 18, 2018 9:28 AM

All replies