Blog
Hier poste ich dinge zu Themen die mich beschäftigten.
Suchen
2024-03-04
HW und SW auslesen und exportieren
# Zentralen DFS-Share Pfad definieren
$dfsShare = “C:tmpAusgabe”
# Überprüfen, ob der DFS-Share Pfad existiert
if (-not (Test-Path -Path $dfsShare)) {
Write-Host “Der DFS-Share Pfad existiert nicht.”
exit
}
$computerName = $env:COMPUTERNAME
$hwOutputPath = Join-Path -Path $dfsShare -ChildPath ($computerName + “_HW.csv”)
$swOutputPath = Join-Path -Path $dfsShare -ChildPath ($computerName + “_SW.csv”)
try {
# Computerinformationen sammeln
$computerInfo = Get-ComputerInfo
$computerInfoProperties = $computerInfo | Get-Member -MemberType Property | Select-Object -ExpandProperty Name
# Formatierung und Export der Computerinformationen
$formattedComputerInfo = @()
foreach ($prop in $computerInfoProperties) {
$value = $computerInfo.$prop
# Beispiel für eine spezifische Formatierung (weitere Bedingungen können hinzugefügt werden)
if ($prop -like “*Memory*”) {
$value = [Math]::Round($value / 1GB, 2)
}
$formattedComputerInfo += New-Object psobject -Property @{
Property = $prop
Value = $value
}
}
$formattedComputerInfo | Export-Csv -Path $hwOutputPath -NoTypeInformation -Force
# Softwareinformationen sammeln und formatieren
$softwareInfo = Get-WmiObject -Class Win32_Product | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Version = $_.Version
Vendor = $_.Vendor
}
}
# Softwareinformationen in CSV exportieren
$softwareInfo | Export-Csv -Path $swOutputPath -NoTypeInformation -Force
} catch {
Write-Host “Fehler beim Sammeln oder Schreiben der Systeminformationen.”
}
Admin - 16:36:37 @ Projekte, Powershell-Skripte | Kommentar hinzufügen
Kommentar hinzufügen
Die Felder Name und Kommentar sind Pflichtfelder.