Mar-10-2024, 04:53 PM
You need to be careful about "\" in string literals because backslash before some characters is the start of an escape sequence, while in front of other characters is just a backslash. "\\" is a single backslash. "\c" is not an escape sequence, but I had to look it up. When using backslashes in a string, as a backslash, use raw string to be safe.
I don't know if any of the network drive parts are correct, but this is how I would write.
I don't know if any of the network drive parts are correct, but this is how I would write.
script_file = 'C:/Scripts/somescript/Connect-0.ps1' with open(script_file, 'w') as file : file.write( '$net = new-object -ComObject WScript.Network\n' fr'$net.MapNetworkDrive("Z:", "\\{host_name}\c$", $false, "domain\USER", "SOMEPASS")\n' ) print(subprocess.call(script_file))