#First PS Script, not populating popup window with desired info

7 messages · Page 1 of 1 (latest)

carmine edge
#

hi,

i am trying to write a script to get the disk storage available on someone's C: and present it in a popup window.

the code seems to run and execute till the end, giving me the popup, however it is not populating the window with the information intended to be stored in my $space variable.

please advise, thanks!

# Write script to get disk space, and provide the amount of space left in a pop-up window 

# Get-PSDrive C | Select-Object Free

Get-PSDrive C | Select-Object Free {
    $space | Select-Object Root,
        @{Name='Free'; Expression={[math]::Round(($space.Free / 1GB), 2)}}
}

# Write-Host $space

$shell =New-Object -ComObject WScript.Shell

$shell.Popup("You have $space remaining on your C: drive")
west cypress
#

is "you" the user executing the script?

#

where is $space assigned?

#

in fact that select statement is just a tangled mess

#
$drive = Get-PSDrive C
$space = [math]::Round(($drive.Free / 1GB), 2)

$shell = New-Object -ComObject WScript.Shell
$shell.Popup("You have $space remaining on your C: drive")
carmine edge
# west cypress in fact that select statement is just a tangled mess

huge thanks for pointing me in the right direction, my logic was similar to yours in the initial declarations and was trying to figure out how to select the space and do the conversion via ChatGPT which lead to the mentioned verbose mess haha, this is way cleaner thanks again

west cypress
#

no problem, glad it helped 🙂