none
Create a variable using powershell

    Question

  • Hi there

    I am trying to create a variable during SCCM deployment to find whether an HBA card is installed on the system, so I can install specific software. I am using the Get-initiatorPort looking for the SAS connection type

    I am trying, the following line, get no error but no variable is created.

    cmd /c powershell.exe -executionpolicy bypass -command "& {$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment; $tsenv.Value('HBAPresent')} = (Get-initiatorPort | ? { $_.ConnectionType -eq 'SAS' })

    what am I doing wrong?


    -- Adam

    • Moved by jrv Thursday, May 31, 2018 1:44 AM correct forum
    Thursday, May 31, 2018 12:09 AM

All replies

  • cmd /c powershell.exe -executionpolicy bypass -command "$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment; $tsenv.Value('HBAPresent')  = Get-initiatorPort | ? { $_.ConnectionType -eq 'SAS' }"



    \_(ツ)_/


    • Edited by jrv Thursday, May 31, 2018 12:15 AM
    Thursday, May 31, 2018 12:14 AM
  • thanks for the reply

    I am getting an error this time

    cmd /c powershell.exe -executionpolicy bypass -command "$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment; $tsenv.Value('HBAPresent') = Get-initiatorPort | ? { $_.ConnectionType -eq 'SAS'}"


    Exception setting "Value": Cannot convert the "System.Object[]" value of type "Object[]" to type "string".
    At line:1 char:61
    + ... nvironment; $tsenv.Value('HBAPresent') = Get-initiatorPort | ? { $_.C ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
        + FullyQualifiedErrorId : RuntimeException


    -- Adam

    Thursday, May 31, 2018 1:35 AM
  • That is not a PowerShell variable.  I will move this to the correct forum for your issue.


    \_(ツ)_/

    Thursday, May 31, 2018 1:44 AM
  • First, there is no reason to use cmd.exe to call another exe -- while it of course technically works, it's redundant and can lead to pathing issues.

    Next, the task sequence environment is only available during the execution of a task sequence. So, are you trying to run the above in a task sequence? If not, it's not valid. What's your intent for this variable though? 


    Jason | https://home.configmgrftw.com | @jasonsandys

    Thursday, May 31, 2018 1:41 PM
    Moderator
  • Yes, I am trying to identify the presence of an LSI RAID card during the TS execution

    -- Adam

    Friday, June 1, 2018 3:21 PM
  • OK, you need to assign a string and not an object array to the variable then.

    Jason | https://home.configmgrftw.com | @jasonsandys

    Friday, June 1, 2018 3:33 PM
    Moderator
  • powershell.exe -executionpolicy bypass -command "
    $tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment;
    $tsenv.Value('HBAPresent')  = (Get-initiatorPort -ConnectionType SAS).Name" 
    Line breaks for clarity - remove them

    \_(ツ)_/


    • Edited by jrv Friday, June 1, 2018 3:42 PM
    Friday, June 1, 2018 3:42 PM
  • Still getting the same "unable to convert to string error", so I will just skip that, I will have to find another way.

    thanks for the help, regardless.


    -- Adam

    Monday, June 4, 2018 3:42 PM