none
Powershell script modify RRS feed

  • Question

  • I am modifying an exiting powershell script other person wrote.

    at the top of the powershell, it  looks like this:

    [CmdletBinding()]
    param (
        [switch]$isTest
    )
    $locMod = ""
    if ($isTest) {
        $locMod = "test"
    }
    $outloc = '\\remoteserver\sis{0}\Project\OUT' -f $locMod
    $output = "$outloc\myfile.csv"
    $outlog = "$outloc\mylog.txt"

    ..........

    Now I would like to modify the script to use a local drive:

    Instead of using \\remoteserver\sis{0}\Project\OUT but just use : c:\export.

    This does not matter it is a test server or prod, for they exist for both.

    so I am thinking to change it to:

    [CmdletBinding()]

    $outloc = 'c:\export'  
    $output = "$outloc\myfile.csv"
    $outlog = "$outloc\mylog.txt"

    I don't need to check isTest or not, what should I remove:

    I think to remove the following lines in bold, but not sure.

    [CmdletBinding()]
    param (
        [switch]$isTest
    )
    $locMod = ""
    if ($isTest) {
        $locMod = "test"
    }
    $outloc = '\\remoteserver\sis{0}\Project\OUT' -f $locMod
    $output = "$outloc\myfile.csv"
    $outlog = "$outloc\mylog.txt"

    Please advice.

    Is still [CmdletBinding()] necessary, can it exist without param() line?


    Thanks



    • Edited by msloy Monday, November 18, 2019 8:12 PM
    Monday, November 18, 2019 8:07 PM

Answers

  • Remove these lines:

      param (
          [switch]$isTest
      )
      $locMod = ""
      if ($isTest) {
          $locMod = "test"
      }

    Replace this line:

      $outloc = '\\remoteserver\sis{0}\Project\OUT' -f $locMod

    with:

      $outloc = 'c:\export'

    Leave the [CmdletBinding()] alone. Whether or not it has any use in this script can't be inferred from the code you've posted. However, even it it isn't affecting anything, niether is is harming anything.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Marked as answer by msloy Monday, November 18, 2019 9:06 PM
    Monday, November 18, 2019 8:34 PM

All replies