TP1
This commit is contained in:
33
scripts/audit_system.ps1
Normal file
33
scripts/audit_system.ps1
Normal file
@@ -0,0 +1,33 @@
|
||||
# audit_system.ps1
|
||||
|
||||
$Date = Get-Date -Format 'dd/MM/yyyy HH:mm'
|
||||
$ComputerName = $env:COMPUTERNAME
|
||||
$User = $env:USERNAME
|
||||
$OS = (Get-CimInstance -ClassName Win32_OperatingSystem).Caption
|
||||
$CPU = (Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name) -join ', '
|
||||
$RAM = (Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory / 1GB
|
||||
|
||||
# Determine script directory (works when run from console or as a script)
|
||||
$ScriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { (Get-Location).ProviderPath }
|
||||
$ExportDir = Join-Path $ScriptDir 'exports'
|
||||
New-Item -Path $ExportDir -ItemType Directory -Force | Out-Null
|
||||
$FilePath = Join-Path $ExportDir 'system_info.txt'
|
||||
|
||||
$Rapport = @"
|
||||
===== RAPPORT SYSTEME =====
|
||||
Machine : $ComputerName
|
||||
Utilisateur : $User
|
||||
OS : $OS
|
||||
Processeur : $CPU
|
||||
RAM (Go) : $([math]::Round($RAM,2))
|
||||
Date : $Date
|
||||
===========================
|
||||
"@
|
||||
|
||||
Try {
|
||||
$Rapport | Out-File -FilePath $FilePath -Encoding UTF8 -Force
|
||||
Write-Host "Rapport généré dans $FilePath" -ForegroundColor Green
|
||||
} Catch {
|
||||
Write-Host "Erreur lors de la génération du rapport: $($_.Exception.Message)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user