如何使用 Powershell 处理 Windows 10 上的 LogonHours 属性?

问题描述

我在阅读 logonHours 属性时遇到了问题,希望得到任何帮助。

在我安装了 RSAT.ActiveDirectory 的服务器或任何计算机上,我可以使用 def execute(accesstoken,messageID,files,noAttachments): import os from os import path import requests import base64 import json if noAttachments == "False": url = 'https://graph.microsoft.com/v1.0/users/{{users email}}/messages/{{messageID}}/attachments' body = {} head = {"Authorization": "Bearer " + accesstoken} responseCode = requests.request("GET",url,headers=head,data = body) response = responseCode.text test = json.loads(responseCode.text.encode('utf8')) x,contentBytes = response.split('"contentBytes":"',1) if len(files) == 1: imgdata = base64.b64decode(str(contentBytes)) filename = "C:/Temp/SAPCareAttachments/" + files[0] with open(filename,'wb') as f: f.write(imgdata) else: for file in test["value"]: imgdata = base64.b64decode(file["contentBytes"]) if file["name"] in files: filename = "C:/Temp/" + file["name"] with open(filename,'wb') as f: f.write(imgdata) print(responseCode) 进行读取,以更人性化的方式在位/字节格式之间进行操作和操作。

但我需要从大多数没有安装 RSAT 的网络中的任何/所有工作站读取它,我认为在每台机器上安装它没有意义。

谷歌搜索,我找到了一种 WMI 方法获取这样的属性 Get-ADUser -Identity 'user' -Property logonHours

我希望以与字节数组类似的格式获取值,其中 168 位表示此处记录的一周中的小时数 (Docs.MS.CIM_Win32_NetworkLoginProfile#LogonHours)。但是相反,我得到了类似波纹管的东西,由于时区差异和混乱结果的问题,这是不可能操作的,例如,星期一的第一个小时实际上是星期天的 1900 点:

Get-WMIObject -Class 'Win32_NetworkLoginProfile' -Property logonHours -Filter "Caption Like '$Env:UserName'"
# net user username /time:w-su,8-18
# Get-WMIObject -Class 'Win32_NetworkLoginProfile' -Property logonHours -Filter "Caption Like '$Env:UserName'"
-- Sunday: 300,400,500,600,700,800,900,1000,1100,1200,-- Monday: Access Denied
-- Tuesday: Access Denied
-- Wednesday: 300,-- Thursday: 300,-- Friday: 300,-- Saturday: 300,1200

我不是开发人员,现在我正在使用 Powershell,因为它对我们的团队更方便,但我认为我们将能够处理一些简单的 c# vb.net 代码以满足非常特定的需求,但是,我试图在任何语言上找到一些关于它的东西,但没有找到任何东西。

感谢任何可以提前提供帮助的人。

丰富

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)