次の入力を受け入れるスクリプトがあります
「送信者-ip=10.10.10.10」
最後にログオンしたユーザーを返すことになっています。
まず、オペレーティング システムの検出を試みます。
次に、ユーザー プロファイルの検出を試みます。
最後に、セキュリティ識別子をユーザー アカウント、つまり DOMAIN\username に変換しようとします。
ここにコードの関連部分があります
$Sender_IP = $my_hash.Get_Item("sender-ip")
try
{
<#Gather information on the computer corresponding to $Sender_IP#>
$Win32OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Sender_IP -ErrorAction Stop
}
catch [Exception]
{
$userId = "Unknown/CannotDetectOS "
return $output = "userId=" + $userId
}
try
{
$Win32User = Get-WmiObject -Class Win32_UserProfile -ComputerName $Sender_IP -ErrorAction Stop
}
catch [Exception]
{
$userId = "Unknown/CannotDetectUserProfile "
return $output+= "userId=" + $userId
}
$Win32User = $Win32User | Sort-Object -Property LastUseTime -Descending
$LastUser = $Win32User | Select-Object -First 1
try
{
$UserSID = New-Object System.Security.Principal.SecurityIdentifier($LastUser.SID)
$userId = $UserSID.Translate([System.Security.Principal.NTAccount])
}
catch [Exception]
{
$userId = "Unknown/CannotDetectUserSID "
return $output = "userId=" + $userId
}
$userId = $userId.Value
if ($userId -ne $NULL){
$output = "userId=" + $userId
}
elseif ($userID -eq $NULL)
{
$userId = "Unknown/UserID"
$output = "userId=" + $userId
}
$output.replace("\","/")
私が理解していることから、Windowsオペレーティングシステムを検出するには、WMIサービスをオンにする必要があります。
$Win32OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Sender_IP -ErrorAction Stop
および Windows ユーザー プロファイル、つまり
$Win32User = Get-WmiObject -Class Win32_UserProfile -ComputerName $Sender_IP -ErrorAction Stop
しかし、セキュリティ識別子を適切に変換するには、どのサービスを有効にする必要がありますか?
$Win32User = $Win32User | Sort-Object -Property LastUseTime -Descending
$LastUser = $Win32User | Select-Object -First 1
try
{
$UserSID = New-Object System.Security.Principal.SecurityIdentifier($LastUser.SID)
$userId = $UserSID.Translate([System.Security.Principal.NTAccount])
}
catch [Exception]
{
$userId = "Unknown/CannotDetectUserSID "
return $output = "userId=" + $userId
}
ある週、「sender-ip=10.10.10.10」でスクリプトを実行して実際のユーザーを取得すると、次の週のスクリプトは「CannotDetectUserProfile」をスローし、次の週のスクリプトは「CannotDetectOS」などをスローします。
どのサービスをオンにする必要がありますか? PowerShell を使用してリモートでこれを実行できますか?