logging for error messages when creating users
This commit is contained in:
parent
f793973571
commit
2fd2bb3630
@ -82,6 +82,9 @@ if ($exePathCheck === null) {
|
|||||||
exec($cmd . ' 2>&1', $output, $returnVar);
|
exec($cmd . ' 2>&1', $output, $returnVar);
|
||||||
$json = implode("\n", $output);
|
$json = implode("\n", $output);
|
||||||
|
|
||||||
|
// Optional: write raw output into logs for debugging
|
||||||
|
@file_put_contents(__DIR__ . '/../logs/create_user_output.log', date('Y-m-d H:i:s') . ' CMD: ' . $cmd . "\n" . $json . "\n\n", FILE_APPEND | LOCK_EX);
|
||||||
|
|
||||||
@unlink($tmpFile);
|
@unlink($tmpFile);
|
||||||
|
|
||||||
// Try to parse JSON output
|
// Try to parse JSON output
|
||||||
|
|||||||
@ -80,6 +80,9 @@ $json = implode("\n", $output);
|
|||||||
@unlink($tmpFile);
|
@unlink($tmpFile);
|
||||||
@unlink($metaFile);
|
@unlink($metaFile);
|
||||||
|
|
||||||
|
// Optional: log the CSV script command and raw output to help debugging
|
||||||
|
@file_put_contents(__DIR__ . '/../logs/create_users_csv_output.log', date('Y-m-d H:i:s') . ' CMD: ' . $cmd . "\n" . $json . "\n\n", FILE_APPEND | LOCK_EX);
|
||||||
|
|
||||||
$result = null;
|
$result = null;
|
||||||
if ($json !== '') {
|
if ($json !== '') {
|
||||||
$decoded = json_decode($json, true);
|
$decoded = json_decode($json, true);
|
||||||
|
|||||||
@ -14,7 +14,8 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Default result
|
# Default result
|
||||||
$result = @{ success = $false; message = "Unspecified error" }
|
$actor = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
||||||
|
$result = @{ success = $false; message = "Unspecified error"; actor = $actor }
|
||||||
|
|
||||||
# Validate
|
# Validate
|
||||||
if (-not $payload.samaccountname -or -not $payload.password) {
|
if (-not $payload.samaccountname -or -not $payload.password) {
|
||||||
|
|||||||
@ -44,6 +44,7 @@ try {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$actor = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
||||||
$results = @()
|
$results = @()
|
||||||
$successCount = 0
|
$successCount = 0
|
||||||
$failCount = 0
|
$failCount = 0
|
||||||
@ -92,6 +93,6 @@ foreach ($row in $items) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = @{ success = $failCount -eq 0; message = "Created $successCount users, $failCount failures"; details = $results }
|
$output = @{ success = $failCount -eq 0; message = "Created $successCount users, $failCount failures"; details = $results; actor = $actor }
|
||||||
Write-Output ($output | ConvertTo-Json -Compress)
|
Write-Output ($output | ConvertTo-Json -Compress)
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user