$paths = @(
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
Get-ItemProperty $paths -ErrorAction SilentlyContinue |
Where-Object DisplayName |
Select-Object DisplayName, UninstallString, QuietUninstallString |
Format-ListCategory Archives: PowerShell
Logoff desktop shortcut for all users on Windows Server
Request admin (UAC) access from Windows batch (.bat) file
Put the following code snippet into the top of your bat file. PowerShell is required.
"%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
IF %ERRORLEVEL% NEQ 0 (
powershell -Command "Start-Process -Verb RunAs -FilePath '%0' -ArgumentList '%*'"
exit /b
)
Append value to Multi SZ Registry value using PowerShell
In the sample bellow the PowerShell script will append a service into RemoteAccessCheckExemptionList in registry. It also checks whether the value already exists there or not.
$subkey = 'SYSTEM\CurrentControlSet\Control\SecurePipeServers\SCM'
$value = 'RemoteAccessCheckExemptionList'
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server)
$key = $reg.OpenSubKey($subkey, $true)
$list = $key.GetValue($value)
if ($list -notcontains 'MyServiceName') {
$list += 'MyServiceName'
}
$key.SetValue($value, [string[]]$list, 'MultiString')
Test SMTP server on Windows using PowerShell
Quick test to find out whether you setup the SMTP server correctly.
Send-MailMessage -SMTPServer localhost -To [email protected] -From [email protected] -Subject "Test" -Body "Test"
Delete folders older than X days using PowerShell
If you need to remove X days old folders from a command line here is a short PowerShell command which will take care of it.
PowerShell -Command "& Get-ChildItem "%1" | Where-Object {$_.PSIsContainer -and $_.LastWriteTime -le [System.DateTime]::Now.AddDays(-%2)} | Remove-Item -Recurse -Force"
Just replace %1 with a base folder and %2 with number of days.
