Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Drives mounted as Unavailable on the remote machine using Invoke-Command

$
0
0

Hi Everyone,

After installing the latest Windows updates, I'm facing an issue when I try to mount a network drive on a remote machine using theInvoke-Command cmdlet.

My requirement is to run the mount command from Python, so I'm launching a PS script which takes the remote machine's credentials, and execute the command using Invoke-Command.

Tried executing the commands directly from PS Console:

>>> $cred = Get-Credential administrator

>>>

>>> Invoke-Command -ScriptBlock {net use} -ComputerName xxx.xxx.xxx.xxx -Credential $cred

New connections will be remembered.

There are no entries in the list.

>>>

>>> Invoke-Command -ScriptBlock {net use X: \\SHARE /user:domain\username password /persistent:YES /y} -ComputerName xxx.xxx.xxx.xxx -Credential $cred
The command completed successfully.

>>>

>>> Invoke-Command -ScriptBlock {net use} -ComputerName xxx.xxx.xxx.xxx -Credential $cred
New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
Unavailable  X:        \\SHARE       Microsoft Windows Network
The command completed successfully.

>>>

The share is only accessible inside the ScriptBlock, but not after, or within the PSSession, if I use Enter-PSSession.

--------------------------------------------------------------------------------------------------------------------------------------------

PS C:\WINDOWS\system32> Invoke-Command -ScriptBlock {gdr; net use X: \\SHARE /user:domain\username password /persistent:YES /y; net use; gdr} -ComputerName xxx.xxx.xxx.xxx -Credential $cred -HideComputerName

Name           Used (GB)     Free (GB) Provider      Root                                              CurrentLocation
----           ---------     --------- --------      ----                                              ---------------
A                                                    A:\
Alias
C                  54.37         95.28               C:\                                 Users\Administrator\Documents
Cert                                                 \
D                                                    D:\
E                 119.87         30.13               E:\
Env
Function
HKCU                                                 HKEY_CURRENT_USER
HKLM                                                 HKEY_LOCAL_MACHINE
Variable
WSMan
The command completed successfully.

New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK           X:        \\SHARE       Microsoft Windows Network
The command completed successfully.

A                                                    A:\
Alias
C                  54.37         95.28               C:\                                 Users\Administrator\Documents
Cert                                                 \
D                                                    D:\
E                 119.87         30.13               E:\
Env
Function
HKCU                                                 HKEY_CURRENT_USER
HKLM                                                 HKEY_LOCAL_MACHINE
Variable
WSMan
X                 152.07        323.13               X:\


PS C:\WINDOWS\system32>

--------------------------------------------------------------------------------------------------------------------------------------------


Same happens even if I use CredSSP, which shouldn't even matter here as per my opinion, because I'm already passing the credentials to the net use command.

I got the same results with New-PSDrive cmdlet as well as with PsExec.

It only worked with if I passed the -s flag, i.e., as SYSTEM account to PsExec.



Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>