Declaring parameters and combining them

Welcome Forums General PowerShell Q&A Declaring parameters and combining them

Viewing 1 reply thread
  • Author
    • #185282
      Topics: 5
      Replies: 3
      Points: 70
      Rank: Member

      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 {
      $ComputerName = $env:COMPUTERNAME)
      process {
      $diskList = get-wmiobject Win32_LogicalDisk -Filter “DriveType = 3”
      foreach ($disk in $diskList){
      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’;


      ‘; ‘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’=’


      ‘; ‘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 a txt file in a 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 $wsh.popup.overloaddefinitions $wsh.popup(” HTML report is ready. Please check it in chrome browser”,10,”Powershell Automation”,0+64)
    • #185288
      Topics: 12
      Replies: 1618
      Points: 2,543
      Helping Hand
      Rank: Community Hero

      Try being a little clearer on what exactly is or is not working, but are you referring to setting the same parameters over and over again? The splatting of parameters is using hash tables, so you can look at managing hash tables to .Add parameters, .Remove parameters or Setting (.Set_Item) on a parameter to leverage a one parameter set and manipulate it.

      #Define original params
      $params = @{
          'PreContent'='SERVIS LOGS';
          'Properties'='Displayname','Name',@{n='Service Status';e={$_.Status};css={if ($_.Status -eq "Stopped") { 'red' } else {'green'}}}
      'First parameter...'
      'Update the PreContent key...'
      $params.Set_Item('PreContent', 'Next Header')
      'Second parameter...'


      PS C:\Users\rasim\Desktop> C:\Users\rasim\Desktop\test.ps1
      First parameter...
      Update the PreContent key...
      Second parameter...
      Next Header
Viewing 1 reply thread
  • The topic ‘Declaring parameters and combining them’ is closed to new replies.