Get-WmiObject delay outcome when check C disk storage

Viewed 20

Get-WmiObject delay outcome when check C disk storage.

When I input my computer name and type '1' to check the C disk storage, the first time won't return the outcome, and I need to type '1' again it will return both the first and second outcome.

However, if I test the function or the line Get-WMIObject separately, it works perfect.

Anyone have any idea what's going on here?

$ComputerNumber = (read-host "Provide computer number").trim()

function Show-Storage{
Get-WmiObject -Class win32_logicaldisk -Filter "DeviceID='C:'" -ComputerName $ComputerNumber|select PSComputerName,DeviceID,@{n='size(GB)';e={$_.size/1gb -as [int]}},@{n='Free(GB)';e={$_.freespace/1gb -as [int]}}
}

function Show-Menu
{
    param (
        [string]$Title = 'Computer Info'
    )
    Write-Host "================ $Title ================"
    Write-Host ""
    Write-Host "1: Press '1' to get Current Computer Usage"
    Write-Host "2: Press '2' to delete Local User Profile"
    Write-Host "Q: Press 'Q' to quit."
}

$a=1
While ($a -eq 1)
{
    write-host ""
    Show-Menu
    write-host ""
    if ($ComputerNumber -ne $null){
        write-host "Selected Computer '$ComputerNumber'"
    }
    else{write-host "No Computer selected"}
    $selection = Read-Host "Please make a selection"

    switch($selection)
    {
    '1'{
        write-host ""
        Show-Storage
        write-host ""
    }
    '2'{
        delete-profile
    }
        'Q'{$a=0}
    }
}

enter image description here

0 Answers
Related