none
How to combine three scripts as one script RRS feed

  • General discussion

  • Hi 

    I am using three different scripts to get CPU load, Physical memory and drive free space for 35 servers. Can some one help me how to combine or help me with PowerShell topic which helps me to combine 

    please find the following scripts  

    #### Script to check CPU Load, Physical memory and disck space #####

    $computers = Get-Content C:\scripts\'xyzhealthcheck.txt' 
    ForEach ($computername in $computers)  {
    $AVGProc = Get-WmiObject  win32_processor -computername $computername |
    Measure-Object -property LoadPercentage -Average | Select-Object Average
    $OS = Get-WmiObject win32_operatingsystem -computername $computername
    $volc = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'C:'"
            $vold = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'D:'"
            $vole = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'E:'"
            $volf = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'f:'"
            $volg = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'g:'"
            $volh = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'h:'"
            $voli = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'i:'"
            $volj = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'j:'"
            $volk = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'k:'"
            $voll = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'l:'"
            $volm = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'm:'"
            $voln = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'n:'"
            $volo = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'o:'"
            $volp = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'o:'"
            $volq = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'q:'"
            $volr = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 'r:'"
            $vols = Get-WmiObject win32_Volume -ComputerName $computername -Filter "DriveLetter = 's:'"

    [pscustomobject]@{
    ComputerName = $computername
    CPUload = $AVGProc.Average
    MemoryUsage =  '{0:N2}' -f ((($os.TotalVisibleMemorySize - $os.FreePhysicalMemory) * 100)/ $os.TotalVisibleMemorySize)
    'CDisk' = (('{0:N2}' -f ($volc.FreeSpace/1gb)) + ' GB') 
                    'DDisk' = (('{0:N2}' -f ($vold.FreeSpace/1gb)) + ' GB') 
                    'EDisk' = (('{0:N2}' -f ($vole.FreeSpace/1gb)) + ' GB') 
                    'FDisk' = (('{0:N2}' -f ($volf.FreeSpace/1gb)) + ' GB') 
                    'GDisk' = (('{0:N2}' -f ($volg.FreeSpace/1gb)) + ' GB') 
                    'HDisk' = (('{0:N2}' -f ($volh.FreeSpace/1gb)) + ' GB') 
                    'IDisk' = (('{0:N2}' -f ($voli.FreeSpace/1gb)) + ' GB') 
                    'JDisk' = (('{0:N2}' -f ($volj.FreeSpace/1gb)) + ' GB') 
                    'KDisk' = (('{0:N2}' -f ($volk.FreeSpace/1gb)) + ' GB') 
                    'LDisk' = (('{0:N2}' -f ($voll.FreeSpace/1gb)) + ' GB') 
                    'MDisk' = (('{0:N2}' -f ($volm.FreeSpace/1gb)) + ' GB') 
                    'NDisk' = (('{0:N2}' -f ($voln.FreeSpace/1gb)) + ' GB') 
                    'ODisk' = (('{0:N2}' -f ($volo.FreeSpace/1gb)) + ' GB') 
                    'PDisk' = (('{0:N2}' -f ($volp.FreeSpace/1gb)) + ' GB') 
                    'QDisk' = (('{0:N2}' -f ($volq.FreeSpace/1gb)) + ' GB') 
                    'RDisk' = (('{0:N2}' -f ($volr.FreeSpace/1gb)) + ' GB') 
                       
        } | Format-Table >>c:\scripts\sun1.txt
    }




    ##############  To check windows services #################


    $data = get-content c:\scripts\xyz-services.txt
    foreach($line in $data) {
    $computer = $line.split(":")[0]
    $ServiceName = $line.split(":")[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
    Get-Service -ComputerName $Computer -Name $ServiceName |  format-table -property MachineName,Status, Name, DisplayName -auto >>c:\scripts\sun21.txt }



    ##############  To check date and time #################


    get-wmiobject win32_localtime -computername (get-content C:\scripts\'xyzhealthcheck.txt') | select-Object __server,month,day,hour,minute | Format-Table -AutoSize








    • Changed type Bill_Stewart Tuesday, November 7, 2017 9:56 PM
    • Moved by Bill_Stewart Tuesday, November 7, 2017 9:57 PM This is not "fix/debug/rewrite my script for me" forum
    Wednesday, September 20, 2017 5:16 PM

All replies