Python Forum
using PowerShell from Python script for mounting shares
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using PowerShell from Python script for mounting shares
#1
Greetings to you all!
I have a list of Hosts, I need to connect to each host and do something with the files on it.
For some reason some of the hosts refusing connection Angry , but I can mount it manually with no problems to my server.

I tried a Power Shell script and it connects without any errors to the Hosts that refusing Python “net use…” connections.
I thought I could create a PS script for each host and then call it from my script.
for some reason it fails with errors:
Directory Does not exists [WinError 32] The process cannot access the file because it is being used by another process
The process cannot access the file because it is being used by another process

here is part of th escript that producess errors:
try :
    call(r"net use Z: /delete /yes")
    ln1= f'$net = new-object -ComObject WScript.Network'
    ln2= f'$net.MapNetworkDrive("Z:", "\\{host_name}\c$", $false, "domain\UsER", "SOMEPASS")'
    with open('C:/Scripts/somescript/Connect-0.ps1','w') as ps :
        ps.write(f"{ln1}\n")
        ps.write(f"{ln2}\n")
        subprocess.call("C:/Scripts/somescript/Connect-0.ps1")
        #break
except OSError as ek :                                              
    print(f" Error - {ek}" )
Any help is appreciated.
Thank you.
Reply


Messages In This Thread
using PowerShell from Python script for mounting shares - by tester_V - Mar-09-2024, 07:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,431 Jun-29-2023, 11:57 AM
Last Post: gologica
  PowerShell & Python deep_logic 2 762 Jun-06-2023, 06:34 AM
Last Post: buran
  How to write a part of powershell command as a variable? ilknurg 2 1,161 Jul-26-2022, 11:31 AM
Last Post: ilknurg
Photo Windows 10 PowerShell doesn't work Amy 3 3,963 Apr-27-2021, 01:33 PM
Last Post: jefsummers
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,998 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,342 May-28-2020, 05:27 PM
Last Post: micseydel
  Package python script which has different libraries as a single executable or script tej7gandhi 1 2,658 May-11-2019, 08:12 PM
Last Post: keames
  Powershell Session translation to Python; Session code seems to not work Maverick494 1 3,640 Jun-26-2018, 05:16 PM
Last Post: Maverick494
  How to run python script which has dependent python script in another folder? PrateekG 1 3,189 May-23-2018, 04:50 PM
Last Post: snippsat
  How to call one python script and use its output in another python script lravikumarvsp 3 32,494 May-16-2018, 02:08 AM
Last Post: lravikumarvsp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020