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
#5
Like this will do, right?

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")
        
except OSError as ek :                                              
    print(f" Error - {ek}" )
Reply


Messages In This Thread
RE: using PowerShell from Python script for mounting shares - by tester_V - Mar-10-2024, 05:21 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,462 Jun-29-2023, 11:57 AM
Last Post: gologica
  PowerShell & Python deep_logic 2 773 Jun-06-2023, 06:34 AM
Last Post: buran
  How to write a part of powershell command as a variable? ilknurg 2 1,169 Jul-26-2022, 11:31 AM
Last Post: ilknurg
Photo Windows 10 PowerShell doesn't work Amy 3 3,982 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 6,015 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,357 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,664 May-11-2019, 08:12 PM
Last Post: keames
  Powershell Session translation to Python; Session code seems to not work Maverick494 1 3,646 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,202 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,502 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