How can I convince powershell (run through task scheduler) to find my network drive?

I have a simple powershell script on Windows 7 that is not working correctly. (this is not a problem for XP)

get-psdrive

When I run it directly, I get

  Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
A                                      FileSystem    A:\
Alias                                  Alias
C                  12.30         11.60 FileSystem    C:\
cert                                   Certificate   \
D                                      FileSystem    D:\
Env                                    Environment
Function                               Function
HKCU                                   Registry      HKEY_CURRENT_USER
HKLM                                   Registry      HKEY_LOCAL_MACHINE
**Q                1486.63        289.41 FileSystem    Q:\**
Variable                               Variable
WSMan                                  WSMan

When I run this through the task scheduler, I get

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
A                                      FileSystem    A:\
Alias                                  Alias
C                  12.30         11.60 FileSystem    C:\
cert                                   Certificate   \
D                                      FileSystem    D:\
Env                                    Environment
Function                               Function
HKCU                                   Registry      HKEY_CURRENT_USER
HKLM                                   Registry      HKEY_LOCAL_MACHINE
Variable                               Variable
WSMan                                  WSMan

Please note that I am missing my Q: drive. If there is a way to solve this problem, I can copy the files there ....

+3
source share
2 answers

Perhaps before running get-psdrive in a script, first do something like this:

$net = new-object -comobject Wscript.Network
$net.mapnetworkdrive("Q:","\\path\to\share",0,"domain\user","password")

and after doing your work (copying files ..):

$net.removenetworkdrive("Q:")
+1
source

, , "" . , ( ) . , Q- - , , , Windows , C: ( ) .

PowerShell, , , . cmd.exe, PowerShell UNC-:

cd \\server\share\directory

, , ? - , Q: (,\server\share), script - :

copy c:\logs\*.log \\server\share\logs

, .

, . , , . , , Windows 7/Server 2008 R2.

: :

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

-command copy c:\logs\*.log \\server\share\logs
+6

Source: https://habr.com/ru/post/1772188/


All Articles