1

I am learning as I go, this is a small part in a large project but its an inconvenience for me

I am working on a script and one of its functions is to output information about the system.

Now ideally this is the command I would like to use to generate a report of connected drives over 60GB. It lists everything I want.

$size = 60GB

Get-Volume | Where-Object {$_.Size -gt $Size} | Sort-Object {$_.DriveLetter}

I am aware of other commands. They all seem to react the same way to being in a function. So that means I just don't understand what that reason is or how to control that.

If somebody could explain to me why this command outputs differently inside of a function. I've tried Googling however I cannot seem to find anything online. I believe its 100% me not knowing what to Google.

Function ProductConfirmation {
    $processor = (Get-ComputerInfo).CsProcessors.Name
    $product = (Get-WmiObject win32_baseboard).Product
    $gpuname = (Get-WmiObject win32_videocontroller).Name
    $gpudesc = (Get-WmiObject win32_videocontroller).Description
    systeminfo | Select-String  'BIOS Version', 
                                'Network Card(s)', 
                                'OS Name', 
                                'OS Version', 
                                'System Manufacturer', 
                                'System Model', 
                                'System Type', 
                                'Time Zone'
    

    Write-Host "`nCPU: $processor"
    Write-Host "`nMotherboard: $product"
    Write-Host "`nGPU Name: $gpuname"
    Write-Host "GPU Description: $gpudesc"
    Start-Sleep -s 5
    
    
    
    Write-Host "`n RAM INFORMATION`n"
    Get-CimInstance -Class CIM_PhysicalMemory -ErrorAction Stop | Select    'Manufacturer', 
                                                                            'DeviceLocator', 
                                                                            'PartNumber', 
                                                                            'ConfiguredClockSpeed'
    ''    
    systeminfo | Select-String  'Total Physical Memory'
    Start-Sleep -s 4
    Write-Host "`n Generating Hard Drive Report`n`n`n"
    Write-Host " Double check all drives that should be with this computer are connected." -ForegroundColor RED
    Start-Sleep -s 4
    $size = 60GB
    Get-Volume | Where-Object {$_.Size -gt $Size} | Sort-Object {$_.DriveLetter}
}
ProductConfirmation

Attached are the outputs of both commands run in a VM.

Top - Run in its function Bottom - Run on its own

Screenshot.png

6
  • 1
    Shouldn't it be $_. instead of $.? Commented May 17, 2022 at 18:18
  • We can't see how your first call to the command is being ran, are you sure you're not piping it to a Format-List? Commented May 17, 2022 at 18:23
  • The command that you see on the screen is whats run inside of the function. It does not change, the function "ProductConfirmation" is pasted into terminal or run in the script itll be integrated to later on. Commented May 17, 2022 at 18:34
  • The commands being used inside your produce different output types, you would need to pipe them to Out-Host so they're properly displayed in the console Commented May 17, 2022 at 18:55
  • 1
    Santiago you are my savior! Thank you :D Commented May 17, 2022 at 18:57

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.