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