none
powershell script modification help RRS feed

  • Question

  • i have powershell script available. it changes advertisement schedule. I am looking some one to modify the script.

    $d=New-CMSchedule -Start "8/11/2014 1:00 PM" -Nonrecurring

     Set-CMPackageDeployment -PackageId "00100754" -StandardProgramName "Automated-Reboot" -CollectionName "ITS - SCMS ED5 Central Push PWBG5160" -DeploymentAvailableDay 08/08/2014 -DeploymentAvailableTime 11:45 -DeploymentExpireDay 08/11/2014 -DeploymentExpireTime 05:00 -Schedule $d

    I want to enter all the value specified in the double quto "" (above script)area in CSV file and scripts take it from input in csv file and run.

    Thanks 

    Monday, September 29, 2014 5:12 PM

Answers

All replies

  • If I understand your question, you want to use the data from a CSV file as the parameter values for parameters to a cmdlet/function/script.

    Here is a short prototype/example of one way to do this. Suppose params.csv:


    "Start","PackageId","StandardProgramName","CollectionName"
    "8/11/2014 1:00pm","00100754","Automated-Reboot","ITS - SCMS ED5 Central Push PWBG5160"
    

    Here is a script containing a function that uses the parameters:


    function Test-Func {
      param(
        $Start,
        $PackageId,
        $StandardProgramName,
        $CollectionName
      )
      "Start: $Start"
      "PackageId: $PackageId"
      "StandardProgramName: $StandardProgramName"
      "CollectionName: $CollectionName"
    }
    
    $csvData = import-csv "params.csv"
    $params = @{}
    $csvData.PSObject.Properties | foreach-object {
      $params[$_.Name] = $_.Value
    }
    Test-Func @params
    

    The function gets the row of data from the CSV file and converts it to a hashtable. This is so we can take advantage of splatting to pass the parameters to the function.

    Note that this short example presumes only one row of data in the CSV file.


    -- Bill Stewart [Bill_Stewart]


    Monday, September 29, 2014 5:43 PM
    Moderator
  • Hi Bill

    thanks for reply

    the above query get the data from csv. how it invoke to my script?

    $d=New-CMSchedule -Start "8/11/2014 1:00 PM" -Nonrecurring

     Set-CMPackageDeployment -PackageId "00100754" -StandardProgramName "Automated-Reboot" -CollectionName "ITS - SCMS ED5 Central Push PWBG5160" -DeploymentAvailableDay 08/08/2014 -DeploymentAvailableTime 11:45 -DeploymentExpireDay 08/11/2014 -DeploymentExpireTime 05:00 -Schedule $d

    possible can i get complete query from you.. i am poor in script
    Monday, September 29, 2014 6:08 PM
  • Sorry, but I don't understand your question. The potential solution I posted is only a proof of concept. In addition I am presuming that you have some fundamental understanding about how PowerShell works.


    -- Bill Stewart [Bill_Stewart]

    Monday, September 29, 2014 6:11 PM
    Moderator
  • Hi I create the script... and works fine. Thanks..
    Thursday, October 2, 2014 1:46 PM