🐍 Python 3.10+
Export Network Login Profiles to CSV (Python)
Exports Network Login Profiles (Win32_NetworkLoginProfile) to a timestamped CSV file via wmic.
export_network_login_profile_to_csv.py
#!/usr/bin/env python3
"""
export_network_login_profile_to_csv.py
Exports Network Login Profiles (Win32_NetworkLoginProfile) to a timestamped CSV file using the
built-in `wmic` command, stdlib only.
Usage:
python export_network_login_profile_to_csv.py [output_folder]
"""
import subprocess
import sys
from datetime import datetime
from pathlib import Path
def main() -> None:
out_folder = Path(sys.argv[1]) if len(sys.argv) > 1 else Path(".")
out_folder.mkdir(parents=True, exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
out_path = out_folder / f"network_login_profile_{timestamp}.csv"
result = subprocess.run(
["wmic", "path", "Win32_NetworkLoginProfile", "get", "Name,LastLogon,NumberOfLogons", "/format:csv"],
capture_output=True, text=True, check=False,
)
if result.returncode != 0:
sys.exit(f"wmic failed: {result.stderr.strip()}")
out_path.write_text(result.stdout, encoding="utf-8")
print(f"Exported Network Login Profiles to {out_path}")
if __name__ == "__main__":
main()