Information Retrieval

I am very new to python but not programming. I am trying to automate a ‘certification check’ with regards to new servers but have a few roadblocks due to my newness here. In a nutshell I need to run my script on Server A (utility server) and have it retrieve the information of the target server (newly built server) and write it all out to the file. It works to get all the local information but how do I point it at the target server? Code pasted below.

Import the needed module

import os
import platform
import sys
import psutil

The class LoggingPrinter allows the displaying of messages and
sending them off to a log file from within the code ratehr than
the back hole of the stdout. it does this by using the stdout
and an open file.

class LoggingPrinter:
def init(self, filename, xt):
self.out_file = open(filename, xt)
self.old_stdout = sys.stdout
# this object will take over stdout's job
sys.stdout = self

# executed when the user does a `print`
def write(self, text):
    if text:
        self.old_stdout.write(r'Console' + text + '\n')

# executed when `with` block begins
def __enter__(self):
    return self

# executed when `with` block ends
def __exit__(self, type, value, traceback):
    # we don't want to log anymore. Restore the original stdout object.
    sys.stdout = self.old_stdout

uname = platform.uname()

directory1 = r’c:\Geeks\forGeeks\dingGeeks\liking stuff’
target1 = r"C:\Paskiet\Python\logs\PythonTestFile4.txt"

path1 = r’c:\Paskiet\Python\logs’
file1 = r"\PythonTestFile4.txt"
isPathExist = os.path.isdir(path1)
isFileExist = os.path.isfile(path1+file1)
os.makedirs(directory1, mode=0o777, exist_ok=isPathExist)

print (isPathExist)

print (isFileExist)

get server/system information

with LoggingPrinter(target1, ‘wt’):
print (f"Machine: {uname.machine}")
print (f"Node: {uname.node}")
print (f"CPU Count: {psutil.cpu_count()}")
print(f"Version: {sys.version}")

with LoggingPrinter(target1, ‘at’):
print(“Here is a new line to print and log.”)
print(“Checking whatever needs to be checked in this section.”)

print(“Entering section of program that will be logged.”)
with LoggingPrinter(target1, “at”):
print(“I’ve got a lovely bunch of coconuts.”)
print(“Exiting logged section of program.”)

UPDATE: I found the wmi class and have been reading up on it and i think that solves my issue however it introduces another issue. I can import the needed module and even set a connection (lack of a better phrase) fine. when I then get the information from the class it makes the existing code error at the line - isPathExist = os.path.isdir(path1)

this is what I added after the line uname = platform.uname()

Import the needed module

import wmi
import os
import platform
import sys
import psutil

conn = wmi.WMI()

Operating system & OS version

for os in conn.Win32_OperatingSystem():
print( 'OS : ’ + os.Caption + ", version " + os.Version )

I am not sure this is my best option. If it is then I can use some guidance on why it is breaking the rest.