I am trying to write a powershell script to find if AHCI or IDE is turned on and still I cannot find any perfect solution. I tried doing something like this:
$success = “NO”
$diskinfo = $null
$filepath = “C:\plik.txt”
<#
File path TBD
try {
$diskinfo = Get-Ciminstance Win32_Systemdriver -filter ‘description like “%AHCI%” and state like “%running%”’ | fl *
$success = “YES”
} catch {}
try {
if ($diskinfo -eq $null) {
$diskinfo = Get-WmiObject Win32_Systemdriver -filter ‘description like “%AHCI%” and state like “%running%”’ | fl *
$success = “YES”
}
} catch {}
try {
if ($diskinfo -eq $null) {
$diskinfo = Get-WmiObject Win32_PnPSignedDriver -filter ‘description like “%AHCI%” and issigned = true’ | fl *
$success = “YES”
}
} catch {}
try {
if ($diskinfo -eq $null) {
$diskinfo = Get-WmiObject Win32_PnPSignedDriver -filter ‘description like “%AHCI%” and issigned = true’ | fl *
$success = “YES”
}
} catch {}
if ($diskinfo -eq $null -and $success -eq “YES”) {
$name = hostname
$write = “YES”
$checkTable = $null
$fileContent = $null
try {
$fileContent = Get-Content -path $filepath
$checkTable = $fileContent.split([System.Environment]::NewLine)
} catch {}
foreach ($element in $checkTable) {
if ($element -eq $name) {
"Już jest w pliku"
$write = "NO"
}
}
if ($write -eq "YES" -and $fileContent -ne $null) {
$fileContent + $name | Out-File -FilePath $filepath
}
if ($fileContent -eq $null) {
$fileContent + $name | Out-File -FilePath $filepath -NoClobber
}
}
else {
if ($success -eq “YES”) {
“AHCI wlaczone”
}
else {
“Nie udało się pobrać informacji”
}
}
I am not sure if it works properly and cannot find anything better in powershell so I thought if someone can help me with creating a similiar script in BIGFIX.
It would help me a lot because it would save time with booting every single device and checking in BIOS if AHCI is on. Thanks in advance.