I can't create a PowerShell file, and I can only use an existing .bat file.
Here is my PowerShell script, which checks if there is a hdd hard drive and return a boolean.
$partitions = Get-CimInstance Win32_DiskPartition
$physDisc = get-physicaldisk
$arr = @()
foreach ($partition in $partitions){
$cims = Get-CimInstance -Query "ASSOCIATORS OF `
{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} `
WHERE AssocClass=Win32_LogicalDiskToPartition"
$regex = $partition.name -match "(d+)"
$physDiscNr = $matches[0]
foreach ($cim in $cims){
if($cim.deviceID -ne "C:" -and $cim.deviceID -ne "D:") {
$arr += [PSCustomObject]@{
MediaType = $($physDisc | ? {$_.DeviceID -eq $physDiscNr} | select -expand MediaType)
}
}
}
}
($arr).MediaType -contains "hdd"
I did not find how to write correctly my script inside the Batch instruction powershell.exe
@ECHO off
powershell.exe "My powershell script here">temp.txt
set /p areFullSSD=<temp.txt
if NOT %areFullSSD%==False goto :noSSD
ECHO areFullSSD
:noSSD
ECHO test
PAUSE
Thank you for the help.
question from:
https://stackoverflow.com/questions/65915349/write-powershell-script-inside-a-bat-file 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…