Arrange output in order using powershell RRS feed

  • Question

  • Dear All,

    i am trying to get System and Disk info on powershell, while generating output i'm getting output as paragraph, i want to suppurate in line by line, please help

    Here is the code

    $freeSpaceFileName = "C:\Powrshell\FreeSpace.htm" 
    $serverlist = "C:\Powrshell\server.txt" 
    $warning = 90 
    $critical = 75 
    New-Item -ItemType file $freeSpaceFileName -Force 
    Function writeDiskInfo 
    $usedSpace = $totSpace - $frspace 
    $freePercent = ($frspace/$totSpace)*100 
    $freePercent = [Math]::Round($freePercent,0) 
    foreach ($server in Get-Content $serverlist) 
     $dp = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter "DriveType = 3"
    [wmi]$sysInfo = get-wmiobject Win32_ComputerSystem -Namespace  "root\CIMV2" -ComputerName $server 
      $Sunname = [string]$sysInfo.name
      $services = Get-Service -ComputerName $Sunname -Name 'AxInstSV', 'AdobeARMservice' , 'AJRouter', 'ApHidMonitorService', 
      'AppReadiness', 'AppHostSvc', 'AppIDSvc', 'Appinfo', 'ALG',
       'AppMgmt', 'BrokerInfrastructure'| Select Name , DisplayName , Status 
     foreach ($item in $dp) 
    $servicename = ''
    $servicestatus = ''
    $ServerIP = ''
    $Sunnamehostname = ''
    if ($item.DeviceID -eq "C:")
      $servicename = $services.DisplayName 
    if ($item.DeviceID -eq "C:")
      $servicestatus = $services.Status
       if ($item.DeviceID -eq "C:")
      $ServerIP = $Server
      if ($item.DeviceID -eq "C:")
      $Sunnamehostname = $Sunname
    Write-Host  $item.DeviceID  $Sunname $item.FreeSpace $item.Size  $servicename $servicestatus | Convert-OutputForCSV
    writeDiskInfo $freeSpaceFileName $ServerIP $Sunnamehostname $item.DeviceID  $item.VolumeName  $item.FreeSpace $item.Size $servicename $servicestatus | Convert-OutputForCSV

    Present Output

     As it shows, all my service and service status were joining, i want to make in one by one

    Please Help!!


    • Moved by Bill_Stewart Monday, March 12, 2018 9:35 PM Help vampire
    Thursday, February 8, 2018 4:35 AM

All replies

  • I believe Trim will work here, but i'm not sure how to use it!!

    Thursday, February 8, 2018 4:46 AM
  • Hi,

    I suggest to change the logic of your script. Don't use Write-Host. Put all the variables you need into an array of custom PowerShell objects and write your csv using Export-Csv

    Create a custom object:

    # Preparing the object $myObject = New-Object –Type PSObject $myObject | Add-Member –Type NoteProperty –Name "DeviceID" –Value $item.DeviceID $myObject | Add-Member –Type NoteProperty –Name "unname" –Value $unname $myObject | Add-Member –Type NoteProperty –Name "FreeSpace" –Value $item.FreeSpace


    Thursday, February 8, 2018 8:26 AM
  • Hi TobyU,

    Firstly thanks for your reply!

    i'm to loop multiple servers here,  so in this case while generating services status/name will not happen in such case you suggested.

    Thank You!

    Friday, February 9, 2018 1:43 AM