i'm a newbie on powershell and i have come up with the problem in variable assignment:
Below is the script is used to retrieve free space percentage for drive with drivetype equal 3
I can't pass $line to line 6 by retrieving the value from the text file but if I do c: instead the script works perfectly, what's my mistake?
Get-WmiObject -Class Win32_logicalDisk | ? {$_.DriveType -eq '3'} | select deviceid > driveletter.txt
$content = Get-Content driveletter.txt | select-string ':' -simplematch
foreach ($line in $content)
{
"line $line"
$freespace = Get-WmiObject -Class Win32_logicalDisk | ? {$_.DeviceID -eq '**$line**'}
$drive = ($freeSpace.DeviceID).Split("=")
"Your $drive Free Space Percentage is {0:P2}" -f ($freespace.FreeSpace / $freespace.Size)
}