New to scripting and powershell. Need help understanding where I went wrong here. Attempting to initialize or set a disk online testing output gives the same results no matter what the disks actual state is. with a script.
disk_stat.ps1
$hdisk = get-disk | select number, partitionstyle
foreach ($object in $hdisk)
{
if ($object -ne 'MBR')
{
write-host = $object.number,$object.partitionstyle "Needs to be set ONLINE"
exit
}
else
{
write-host = $object.number,$object.partitionstyle "Needs to be initialized"
exit
}
}
from "get-disk | select number, partitionstyle" output =
number PartitionStyle
------ --------------
0 MBR
1 RAW
So my intended output should tell me which number/partition style is Raw, offlineetc..
Output: PS C:\Users\Administrator> C:\Temp\disk_stat.ps1 = 0 MBR Needs to be initialized