Upload Install-WMIC.ps1
Browse files- commandos/Install-WMIC.ps1 +47 -0
commandos/Install-WMIC.ps1
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Define the path to check for WMIC
|
| 2 |
+
$wmicPath = "C:\Windows\System32\wbem\WMIC.exe"
|
| 3 |
+
|
| 4 |
+
# Function to check if WMIC is installed
|
| 5 |
+
function Check-WMIC {
|
| 6 |
+
if (Test-Path $wmicPath) {
|
| 7 |
+
Write-Host "WMIC is already installed at $wmicPath. No action needed." -ForegroundColor Green
|
| 8 |
+
return $true
|
| 9 |
+
} else {
|
| 10 |
+
Write-Host "WMIC is not installed. Proceeding to install it." -ForegroundColor Yellow
|
| 11 |
+
return $false
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
# Function to install WMIC using DISM
|
| 16 |
+
function Install-WMIC {
|
| 17 |
+
try {
|
| 18 |
+
Write-Host "Installing WMIC using DISM..." -ForegroundColor Cyan
|
| 19 |
+
$dismCommand = "DISM /Online /Add-Capability /CapabilityName:WMIC~~~~"
|
| 20 |
+
$process = Start-Process -FilePath "cmd.exe" -ArgumentList "/c", $dismCommand -NoNewWindow -Wait -PassThru
|
| 21 |
+
|
| 22 |
+
if ($process.ExitCode -eq 0) {
|
| 23 |
+
Write-Host "WMIC has been successfully installed." -ForegroundColor Green
|
| 24 |
+
} else {
|
| 25 |
+
Write-Host "WMIC installation failed with exit code $($process.ExitCode). Check DISM logs for details." -ForegroundColor Red
|
| 26 |
+
}
|
| 27 |
+
} catch {
|
| 28 |
+
Write-Host "An error occurred during WMIC installation: $_" -ForegroundColor Red
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
# Function to verify WMIC installation
|
| 33 |
+
function Verify-WMIC {
|
| 34 |
+
$capabilityStatus = Get-WindowsCapability -Online | Where-Object { $_.Name -like "WMIC~~~~" }
|
| 35 |
+
|
| 36 |
+
if ($capabilityStatus -and $capabilityStatus.State -eq "Installed") {
|
| 37 |
+
Write-Host "WMIC installation verified. State: Installed." -ForegroundColor Green
|
| 38 |
+
} else {
|
| 39 |
+
Write-Host "WMIC installation verification failed. State: Not Installed." -ForegroundColor Red
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
# Main script execution
|
| 44 |
+
if (-not (Check-WMIC)) {
|
| 45 |
+
Install-WMIC
|
| 46 |
+
Verify-WMIC
|
| 47 |
+
}
|