Blog
Hier poste ich dinge zu Themen die mich beschäftigten.
2024-03-08
$groups = Get-ADGroup -Filter ‘Name -like “*-Users”‘
foreach ($group in $groups) {
# Get the members of each group
$members = Get-ADGroupMember -Identity $group -Recursive | Get-ADUser -Property Enabled | Where-Object {$_.Enabled -eq $true}
# Output the count of enabled members
Write-Output “Group: $($group.Name) has $($members.Count) enabled members”
}
Admin - 09:54:54 @ Projekte, Powershell-Skripte | Kommentar hinzufügen
2024-03-04
# 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
function Get-MonitorInfo {
$MonitorInfo = Get-WmiObject WmiMonitorID -Namespace rootwmi -ComputerName $env:COMPUTERNAME
$Output = @()
$SeenSerials = @()
foreach ($Monitor in $MonitorInfo) {
$Serial = ($Monitor.SerialNumberID -notmatch ‘^0$’ | ForEach-Object {[char]$_}) -join “”
if ($SeenSerials -contains $Serial) {
continue
}
$SeenSerials += $Serial
$Manufacturer = ($Monitor.ManufacturerName -notmatch ‘^0$’ | ForEach-Object {[char]$_}) -join “”
$Name = ($Monitor.UserFriendlyName -notmatch ‘^0$’ | ForEach-Object {[char]$_}) -join “”
$Output += “Manufacturer: $Manufacturer`nName: $Name`nSerial: $Serial`n”
}
return $Output
}
# Überprüfen des IP-Bereichs vor der Ausführung
$CurrentIP = (Get-NetIPAddress -AddressFamily IPv4).IPAddress
$AllowedIPRange = “192.168.200.*” # Beispiel-IP-Bereich, anpassen nach Bedarf
if ($CurrentIP -like $AllowedIPRange) {
cls
$MonitorInfo = Get-MonitorInfo
# Definieren des Freigabepfads und Erstellen des Dateinamens
$SharedPath = “c:tmp” # Anpassen an Ihren Freigabepfad
$Date = Get-Date -Format “yyyyMMdd”
$FileName = “MonitorInfo_$Date” + “_” + $env:COMPUTERNAME + “.txt”
$FullFilePath = Join-Path -Path $SharedPath -ChildPath $FileName
# Schreiben der Informationen in die Datei im Freigabepfad
$MonitorInfo | Out-File -FilePath $FullFilePath
# Optionale Ausgabe zur Bestätigung
Write-Host “Monitor information saved to $FullFilePath”
} else {
Write-Host “This script is not allowed to run in the current IP range.”
}
Admin - 16:29:45 @ Projekte, Powershell-Skripte | Kommentar hinzufügen
2024-02-20
# Überprüft, ob ein Proxy in den Internet-Explorer-Einstellungen konfiguriert ist
function Test-ProxyConfiguration {
try {
# Abrufen der Proxy-Einstellungen aus dem Internet Explorer
$proxySettings = Get-ItemProperty ‘HKCU:SoftwareMicrosoftWindowsCurrentVersionInternet Settings’
# Überprüfen, ob der Proxy aktiviert ist (ProxyEnable = 1)
if ($proxySettings.ProxyEnable -eq 1) {
$proxyAddress = $proxySettings.ProxyServer
Write-Output “Proxy ist aktiviert. Proxy-Adresse: $proxyAddress”
} else {
Write-Output “Kein Proxy konfiguriert.”
}
} catch {
Write-Output “Fehler beim Abrufen der Proxy-Einstellungen: $_”
}
}
# Ausführen der Funktion
Test-ProxyConfiguration
Admin - 17:09:26 @ Projekte, Powershell-Skripte | Kommentar hinzufügen
2023-06-12
# Liste der Computernamen
$computers = Get-Content -Path “C:pathtoyourcomputers.txt”
foreach ($computer in $computers) {
# Prüfen, ob der Computer erreichbar ist
if (Test-Connection -ComputerName $computer -Count 1 -Quiet) {
# Computerinformationen sammeln
$compInfo = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer | Select-Object Manufacturer, Model, Name, UserName
# Installierte Software sammeln
$software = Invoke-Command -ComputerName $computer -ScriptBlock {
Get-ItemProperty HKLM:SoftwareWow6432NodeMicrosoftWindowsCurrentVersionUninstall*,
HKLM:SoftwareMicrosoftWindowsCurrentVersionUninstall* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, UninstallString |
Where-Object { $_.DisplayName -ne $null }
}
# Informationen in CSV-Dateien schreiben
$compInfo | Export-Csv -Path “C:pathtologs$computer-hardware.csv” -NoTypeInformation
$software | Export-Csv -Path “C:pathtologs$computer-software.csv” -NoTypeInformation
} else {
Write-Host “Cannot reach $computer”
}
}
“`
Dieses Skript sammelt nun Informationen sowohl aus `HKLM:SoftwareWow6432NodeMicrosoftWindowsCurrentVersionUninstall` (für 64-Bit-Software) als auch aus `HKLM:SoftwareMicrosoftWindowsCurrentVersionUninstall` (für 32-Bit-Software). [Mehr lesen…]
Admin - 20:52:34 @ Projekte, Powershell-Skripte | Kommentar hinzufügen
Die an dieser Stelle vorgesehenen Inhalte können aufgrund Ihrer aktuellen Cookie-Einstellungen nicht angezeigt werden.
Diese Webseite bietet möglicherweise Inhalte oder Funktionalitäten an, die von Drittanbietern eigenverantwortlich zur Verfügung gestellt werden. Diese Drittanbieter können eigene Cookies setzen, z.B. um die Nutzeraktivität zu verfolgen oder ihre Angebote zu personalisieren und zu optimieren.
Diese Webseite verwendet Cookies, um Besuchern ein optimales Nutzererlebnis zu bieten. Bestimmte Inhalte von Drittanbietern werden nur angezeigt, wenn die entsprechende Option aktiviert ist. Die Datenverarbeitung kann dann auch in einem Drittland erfolgen. Weitere Informationen hierzu in der Datenschutzerklärung.