Declaring parameters in every case

Welcome Forums General PowerShell Q&A Declaring parameters in every case

Viewing 1 reply thread
  • Author
    Posts
    • #185276
      Participant
      Topics: 3
      Replies: 2
      Points: 44
      Rank: Member

      Hello
      I just started to play around HTML outputs in Powershell and when i read those cmdlets and parameters, my eyes are bleeding as yours will be. My point is that there are some parameters to combine some parameters but i couldn't figure out how. I think that i shouldn't declare parameters for every case.
      Ps: and Yes, i copied some cmdlets from here but i am just learner.

      
      #adding a function to script and describing functionality of function and its parameters.
      
      function Get-DisksSPaceReport {
      [CmdletBinding()]
      param(
      [Parameter(ValueFromPipeline=$true)]
      [ValidateNotNullOrEmpty()]
      [System.String[]]
      $ComputerName = $env:COMPUTERNAME)
      process {
      $diskList = get-wmiobject Win32_LogicalDisk -Filter "DriveType = 3"
      foreach ($disk in $diskList){
      [PSCustomObject]@{
      ComputerName = $disk.PSComputerName
      DriveLetter = $disk.DeviceID
      VolumeName = $disk.VolumeName
      Size = $disk.Size
      FreeSpace = $disk.FreeSpace }}}}
      
      $date = get-date
      
      #params directing inputs and variables as HTML outputs according to css.
      $params = @{'As'='Table';
      'PreContent'='

      SERVIS LOGS

      '; 'MakeTableDynamic'=$true; 'TableCssClass'='grid'; 'Properties'='DIsplayname','name',@{n='Service Status';e={$_.Status};css={if ($_.Status -eq "Stopped") { 'red' } else {'green'}}}} #the google services are converted to HTML according to @params $SPservice = Get-Service -Displayname "*google*" | ConvertTo-EnhancedHTMLFragment @params $params2 = @{'As'='Table'; 'PreContent'='

      EVENT LOGS

      '; 'MakeTableDynamic'=$true; 'TableCssClass'='grid'; 'Properties'='instanceID', @{n='Entry Status';e={$_.Entrytype};css={if ($_.entrytype -eq "warning") { 'red' } else {'orange'}}}} $eventlogs = Get-EventLog System -Newest 25 | ConvertTo-EnhancedHTMLFragment @params2 #params3 declares different values than other params. COnverting capacity and Freespaceses in GB instead of bytes. With if statements, declaring which color they will be assigned by css. $params3 = @{'As'='Table'; 'PreContent'='

      Driver Status

      '; 'MakeTableDynamic'=$true; 'TableCssClass'='grid'; 'Properties'='Computername','DriveLetter', @{Name='Capacity';Expression={[math]::round($_.Size / 1GB,2)}}, @{Name='FreeSpaceIn%';Expression={[math]::round($_.FreeSpace / $_.Size * 100,2)};css={if ($_.Free -gt 100) { 'red '} else {'green'}}}, @{Name='FreeSpaceLessThan10%';Expression={If(($_.FreeSpace / $_.Size * 100) -lt 10){$true}Else{$false}}}, @{Name='FreeSpace';Expression={[math]::round($_.FreeSpace / 1GB,2)}; css={if ($_.Free -gt 100) { 'red '} else {'green'}}}} #getting driver objects $drivers= Get-DisksSPaceReport| Select-Object -Property ComputerName,DriveLetter,VolumeName,Size,FreeSpace | ConvertTo-EnhancedHTMLFragment @params3 #getting all variables in HTML format and applying css file and creating txt file in particular file. ConvertTo-EnhancedHTML -HTMLFragments " $SPservice $eventlogs $Drivers $date" -CssUri C:\Users\A701026\Desktop\sample\styles2.css |Out-File C:\Users\A701026\Desktop\sample\paramexample.html #creating pop up which shows a warning related with result. $wsh = new-object -com wscript.shell $wsh.popup.overloaddefinitions $wsh.popup(" HTML report is ready. Please check it in chrome browser",10,"Powershell Automation",0+64)
    • #185747
      Participant
      Topics: 6
      Replies: 108
      Points: 302
      Helping Hand
      Rank: Contributor

      Are you asking about the hash tables that this script is using to pass the parameters to the ConvertTo-EnhancedHTMLFragment cmdlet?

      $params = @{
          'As'='Table';
          'PreContent'=' SERVIS LOGS';
          'MakeTableDynamic'=$true;
          'TableCssClass'='grid';
          'Properties'='DIsplayname','name',@{n='Service Status';e={$_.Status};css={if ($_.Status -eq "Stopped") { 'red' } else {'green'}}}
      }
Viewing 1 reply thread
  • You must be logged in to reply to this topic.