Cloud

windows winrm 을 사용한 date 확인 본문

인프라관리-코드

windows winrm 을 사용한 date 확인

Firewall 2023. 7. 27. 10:40

#!/usr/bin/env python3

import winrm

try:
    param = argv[1]
except:
    param = "status"

hosts = {'$hostname':'$ip'}
user_id = '$ID'
user_pw = '$password'

def run_pwsh_cmd(pwsh_cmd):
    result_byte = session.run_ps(pwsh_cmd)
    result = result_byte.std_out.decode('utf-8')
    return result 

for hostname, ip in hosts.items():
    session = winrm.Session(ip, auth=(user_id, user_pw))
    date = run_pwsh_cmd('Get-Date')
    print(date)
Comments