Windows-Programm ausführen und Returncode anzeigen:
$process = Start-Process notepad.exe -ArgumentList "C:\path\to\file.txt" -Wait -PassThru
# Retrieve the return code
$process.ExitCode
Nach Werten in der Registry suchen:
function Search-Registry {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$SearchTerm,
[Parameter(Mandatory = $false)]
[string]$Path = 'HKLM:\SOFTWARE'
)
Get-ChildItem -Path $Path -Recurse -ErrorAction SilentlyContinue | ForEach-Object {
$key = $_
# 1. Match Key Name
if ($key.Name -match [regex]::Escape($SearchTerm)) {
[PSCustomObject]@{
Type = 'Key Name'
Path = $key.Name
Name = ''
Value = ''
}
}
# 2. Match Property Names and Values
try {
$key.GetValueNames() | ForEach-Object {
$valueName = $_
$valueData = $key.GetValue($valueName)
if ($valueName -match [regex]::Escape($SearchTerm) -or $valueData -match [regex]::Escape($SearchTerm)) {
[PSCustomObject]@{
Type = 'Value / Data'
Path = $key.Name
Name = $valueName
Value = $valueData
}
}
}
} catch {
# Skip keys that cannot be read due to permissions
}
}
}
# Example Usage:
Search-Registry -SearchTerm "Chrome" -Path "HKLM:\SOFTWARE"

