VOLUME_MOUNT/volume.py

37 lines
1.3 KiB
Python

import subprocess
import json
def get_netvolume():
# PowerShell-Befehl als Zeichenkette
powershell_command = (
"Get-CimInstance -ClassName Win32_LogicalDisk | "
"Where-Object -Property DriveType -EQ 4 | "
"Select-Object DeviceID,ProviderName | "
"ConvertTo-Json"
)
volume_count = ("(Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object -Property DriveType -EQ 4).Count")
# PowerShell-Befehl ausführen und das Ergebnis in eine Python-Variable laden
result = subprocess.run(
["powershell", "-Command", powershell_command],
capture_output=True,
text=True
)
volume_count_result = subprocess.run (
["powershell", "-Command", volume_count],
capture_output=True,
text=True
)
volumes = []
if result.stdout != '':
net_drives = json.loads(result.stdout)
else:
return None
if volume_count_result.stdout != '':
for i in net_drives:
volumes.append(f"{i['DeviceID']};{i['ProviderName']}")
return volumes
else:
volumes.append(f"{net_drives['DeviceID'][0]};{net_drives['ProviderName']}")
return volumes
# Die Ausgabe alvolumess JSON interpretieren und in ein Python-Array laden
print(get_netvolume())