So I'm diving into PowerShell for the first time. trying to just write a BitLocker script that will check the hard disk size before enabling BitLocker. Need a little help with outputting values. Problem I'm having is when im trying print out the values of the current size of the drive calling $test = NewSize Write-host or Write-Output it will skip past it and just move on to confirm
$DiskDrive = $env:SystemDrive
$BLV = Get-BitLockerVolume -MountPoint $DiskDrive
$OnlyDriveLetter = $DiskDrive.Substring(0,1)
$TotalSize = Get-PartitionSupportedSize -DriveLetter $OnlyDriveLetter
$MaxSize = (Get-PartitionSupportedSize -DriveLetter $OnlyDriveLetter).sizeMax
$UsedSize = (Get-PartitionSupportedSize -DriveLetter $OnlyDriveLetter).sizeMin
function NewSize()
{
$NewDriveSize= Get-PartitionSupportedSize -DriveLetter $OnlyDriveLetter
return $NewDriveSize | Select @{Name="Min. Size (GB)"; Expression={[Math]::Round($_.SizeMin/1GB, 2)}}, @{Name="Max Size (GB)";Expression={[Math]::Round($_.SizeMax/1GB, 2)}}
}
function Confirm($stringInput)
{
do
{
choice /c yn /m $stringInput
$response = $LASTEXITCODE
if($response -eq 1)
{
Write-Host "Expanding Drive Size"
#Resize-Partition -DriveLetter $OnlyDriveLetter-Size $TotalSize
Write-Host "New Drive Size is:"
NewSize
exit
}
$response = 2
} until ($response -eq 2)
Write-Output "BitLocker encryption could not Be enabled, Exiting program!"
}
if(($BLV.VolumeStatus -eq 'FullyDecrypted') -and ($UsedSize -lt $MaxSize))
{
$confirmation = "Would you like to expand drive Partition to Maximum Size? "
$NotExtended = "Drive is Decrypted and Partition is not fully Extended"
$sizeOfDrive = "Current Drive Size is: "
$CurrentDriveAllocation = NewSize
Write-Host $NotExtended -ForegroundColor Cyan
Write-Host $sizeOfDrive
$test = NewSize
Write-Host $test
Confirm($confirmation)
}