Category Archives: Microsoft

Informacje nt. produktów rodziny Microsoft

PowerShell – monitorowanie sprawności dysku twardego

Ciekawy skrypt autorstwa Sama Eastmana ( https://www.linkedin.com/pulse/proactive-disk-health-monitoring-powershell-sam-eastman-sjw2c ), który w połączeniu z wysyłaniem loga na maila w przypadku innego statusu niż Healty, jest bardzo ciekawym rozwiązaniem.

<##################################################################################################
Title: Get-DiskInfo

.SYNOPSIS
    Script will query each connected disk and output statistics
###################################################################################################>

# Variables
$directoryPath = "C:\temp"
$logFilePath   = "C:\temp\DiskHealthCheck.log"
$disks         = Get-PhysicalDisk

# Functions
function Get-TempDirectory {
    # Check if the directory exists
    if (-not (Test-Path -Path $directoryPath -PathType Container)) {
        # If the directory does not exist, create it
        New-Item -Path $directoryPath -ItemType Directory
        Write-Host "Directory created: $directoryPath"
    } else {
        Write-Host "Directory already exists: $directoryPath"
    }
}

function Get-DiskInformation {
    foreach ($disk in $disks) {
        # Get Disk Reliability Statistics
        $reliabilityCounters = Get-StorageReliabilityCounter -PhysicalDisk $disk
        
        $logEntry = @"
-----------------------------------------------------------------------------------------
Disk: $($disk.FriendlyName)
Operational Status: $($disk.OperationalStatus)
Temperature: $($reliabilityCounters.Temperature)°C
Wear Level: $($reliabilityCounters.Wear)
Status: $($disk.HealthStatus)
-----------------------------------------------------------------------------------------
"@

        Add-Content -Path $logFilePath -Value $logEntry
    }
}

# Body
Get-TempDirectory
Get-DiskInformation        

SharpUp – narzędzie do audytu bezpieczeństwa systemu Windows

Narzędzie SharpUP zostało napisane przez Willa Schroedera znanego jako Harmj0y. Służy ono do wykrywania podatności pod kątem eskalacji uprawnień w systemie Windows. Wykrywa błędy w konfiguracji systemu, które mogą prowadzić do przejęcie praw administratora przez nieautoryzowanych użytkowników.
Kod źródłowy narzędzia SharpUp jest otwarty i możne go pobrać ze strony: https://github.com/GhostPack/SharpUp.
Kod można skompilować np. za pomocą Microsoft Visual Studio 2022 Community Edition.
Program należy uruchomić z linii komend poleceniem:

SharpUp.exe audit

ESET remover – PowerShell script

Below script allows to remove ESET product from Windows 10 / 11 without system restart nor entering to Recovery  Mode.

#WMI object refreshing
net stop winmgmt /y
winmgmt /resetrepository
net start winmgmt

# retriving GUID for ESET
$eset = Get-CimInstance -ClassName Win32_Product | Where-Object { $_.Name -like "*ESET*" }

$esetVersion = $eset.name
$Win32_Product_query = "SELECT * FROM AntivirusProduct WHERE displayName = '$esetVersion'"
$SecurityCenter2_query = Get-WmiObject -Namespace "root\SecurityCenter2" -Query "SELECT * FROM AntivirusProduct WHERE displayName = 'ESET Endpoint Security'" 
$SecurityCenter2_query2 = Get-WmiObject -Namespace "root\SecurityCenter2" -Query "SELECT * FROM AntivirusProduct WHERE displayName = 'ESET Security'"

if ($eset) {
# display GUID 
$eset | Select-Object Name, IdentifyingNumber
# ESET deinstallation
$msiGuid = $eset.IdentifyingNumber
$msiexecArgs = "/x $msiGuid /quiet /norestart"
Start-Process msiexec.exe -ArgumentList $msiexecArgs -Wait
Write-Host "ESET has been successfully uninstalled."
} 
else {
Write-Host "ESET was not found on this system" -BackgroundColor Green;
}

if ($SecurityCenter2_query) {
$SecurityCenter2_query | Remove-WMIObject
Write-Host "ESET Endpoint Security record was found in the root\SecurityCenter2 namespace. The record has been deleted" -BackgroundColor Green;
}
if ($SecurityCenter2_query2) {
$SecurityCenter2_query2 | Remove-WMIObject
Write-Host "ESET Security record was found in the root\SecurityCenter2 namespace. The record has been deleted" -BackgroundColor Green;
}

#REMOVE POSSIBLE QUARANTINE FOLDERS
$quarantine_folders = @(
"C:\ProgramData\ESET\ESET NOD32 Antivirus\Quarantine",
"C:\ProgramData\ESET\ESET Internet Security\Quarantine",
"C:\User\AppData\Local\ESET\ESET Security"
"C:\Users\Default\AppData\Local\ESET"
)
foreach ($quarantine_folder in $quarantine_folders) {
if (Test-Path $quarantine_folder) {
try {
Remove-Item -Path $quarantine_folder -Recurse -Force
Write-Host "Folder: $quarantine_folder has been deleted." -ForegroundColor Green
} catch {
Write-Host "An error occurred while deleting a folder: $quarantine_folder $_" -ForegroundColor Red
}
}
else {
Write-Host "Folder $quarantine_folder not exist." -ForegroundColor Yellow
} 
}

Instalacja Windows 11 na VMware ESXi 7.0

Przy instalacji Windows 11 na VMware ESXi 7.0 należy nacisnąć klawisze Shift+F10 przy wyborze języka instalacji. Otworzy się okno linii komend, w którym należy wpisać poniższe komendy a następnie zamknąć okno:

reg add HKLM\SYSTEM\Setup\LabConfig /v ByPassTPMCheck /d 1
opcjonalnie:
reg add HKLM\SYSTEM\Setup\LabConfig /v ByPassRAMCheck /d 1
reg add HKLM\SYSTEM\Setup\LabConfig /v ByPassSecureBootCheck /d 1

Link: https://www.robsteele.co/this-pc-cant-run-windows-11-on-esxi-7/

dodatkowo, można wydać polecenie: start ms-cxh:localonly w celu utworzenia konta lokalnego w systemie.

Windows Server 2022 sam się wyłącza. Wyłączenie usługi Windows Licensing Monitoring Service

W środowisku testowym jeśli upłynie okres 180 dni od chwili instalacji Windows Server 2022 system poza wyświetleniem na pulpicie komunikatu o konieczność jego aktywacji po godzinie pracy sam się wyłącza. Aby tego uniknąć należy wyłączyć usługę Windows Licensing Monitoring Service (pol. Usługa Menedżera Licencji Systemu Windows).  W tym celu trzeba pobrać narzędzie PsExec.exe a następnie uruchomić je jako administrator. Po uruchomieniu za pośrednictwem PsExec uruchomić cmd.exe.

PsExec.exe -i -s cmd.exe

Po otwarciu cmd.exe należy uruchomić services.exe, znaleźć usługę WLMS i ją wyłączyć. Po restarcie serwera nie będzie już komunikatów na pulpicie a Windows Server 2022 przestanie się sam wyłączać co godzinę.

Edycja pliku instalatora MSI

Do edycji pliku MSI służą narzędzia MSI Tools z pakietu Microsoft SDK (Software Development Kit, do pobrania pod adresem: https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/.
Po instalacji pakietu należy uruchomić instalator właściwego programu w katalogu:  c:\program files (x86)\Windows Kits\10\bin\10.0.22621\x86\Orca-x86_en-us.
Następnie należy uruchomić edytor plików MSI w katalogu: c:\program files (x86)\Orca\Orca.exe
Microsoft poleca po otwarciu pliku MSI stworzenie jego kopii binarnej – niepracowanie na oryginalnym pliku. W tym celu po otwarciu pliku należy wybrać na górnym pasku opcję Transform -> New Transform.
Narzędzie MS MSI Tools służy do edycji istniejących instalatorów MSI.
Inne narzędzie https://wixtoolset.org/ służy do budowy instalatorów MSI.