Variable not passing through?

Abraham Zinala

Good afternoon all!

May I get some assistance, or at least pointed in the right direction with the below script?

Im working with the Dell BIOS and have successfully been able to get what we're looking for working as far as, getting the remote PC to set a certain category to Disabled, or Enabled. Now the issue is, when trying to create the script, the variable for the selection does pass through and just loops to the first colum of selections. See below:


$PSSession = New-PSSession -ComputerName $CName
Write-Host "Please wait will module is loaded"


Invoke-Command -Session $PSSession {Import-Module DellBIOSProvider} 
Start-Sleep 1

$FConfigs = Invoke-Command -Session $PSSession { Get-ChildItem -path "DellSMBios:\" | Select-Object -ExpandProperty Category}

for ($i=0; $i -lt $FConfigs.Count; $i++) {
  Write-Host "$($i): $($FConfigs[$i])"
  }

$selection1 = Read-Host "Enter the number you'd like to change"
$selection =  $Fconfigs[$selection1]

Start-Sleep 2
$SConfigs = Invoke-Command -Session $PSSession { Get-ChildItem -path "DellSMBios:\$selection" | Select-Object -ExpandProperty Category}
for ($i=0; $i -lt $SConfigs.Count; $i++) {
  Write-Host "$($i): $($SConfigs[$i])"
  }

$selection1 = Read-Host "Enter the number you'd like to change"
$selection =  $Sconfigs[$selection1]
"$selection"        

So in the selection of $FConfigs, $selection gets the appropriate selection but, it doesn't pass through to $SConfigs. That's because, it shows the exact same selection of $FConfigs in $Sconfigs. Please note: I have verified that whatever selection i choose, does have properties in it, so gci "dellsmbios:\$selection" should work.

Hopefully this makes sense, and someone may be able to tell me what i may be doing wrong.

Ianteu
$SConfigs = Invoke-Command -Session $PSSession { Get-ChildItem -path "DellSMBios:\$selection" | Select-Object -ExpandProperty Category}

In this line, change $selection to $using:selection.

You need to do this when using local variables in a remote session. You can read more about it here under 'Using local variables':

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_remote_variables?view=powershell-7.1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Passing a variable through a method in Java

From Dev

Passing variable through URL with angular js

From Dev

Angularjs Passing variable through resolve function

From Dev

Passing an object variable through html

From Dev

Passing defined variable through different scenarios is not working

From Dev

Returning the updated variable passing through private methods

From Dev

Passing variable through Django template url tag

From Dev

Simple function not passing through the variable correctly

From Dev

Passing a context variable through a class in Django

From Dev

Passing variable through pages in WordPress

From Dev

Passing a Variable through NSStatusItem's Action

From Dev

PHP: passing a variable through a link

From Dev

Variable value not passing through loop

From Dev

Passing a string variable through ajax

From Dev

Passing a JavaScript variable to the view through a HTML form

From Dev

Passing a variable through _GET

From Dev

Issue with passing a variable through prepareForSegue method

From Dev

Passing an Environment Variable Through Alacarte?

From Dev

Passing a color through a variable in a canvas animation

From Dev

Custom menu Passing a WorkSheet variable through .OnAction

From Dev

Passing variable to next page through url

From Dev

Passing variable in pages through URL

From Dev

Zend: Passing variable through redirect

From Dev

Passing class with variable through Simple Injector

From Dev

Passing a variable to javascript through HTML Element

From Dev

Passing variable through classes

From Dev

Passing through variable example

From Dev

Passing query string through variable value fails

From Dev

Passing a variable through the form action

Related Related

HotTag

Archive