S
S
SanDn2020-02-29 19:32:10
PowerShell
SanDn, 2020-02-29 19:32:10

[powershell] how to execute what is in a variable?

I apologize, of course, for a stupid question
, but I myself can’t finish something.
Is it possible to somehow execute the text in a variable?
Here I have a text link in a variable to an object in a hash table, for example:
$var = '$ht.key1'
and what should I do to do this?
those. as if I typed this from the keyboard: $ht.key1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
azarij, 2020-02-29
@SanDn

So?

$date = Get-Date
$command = '$date.dayofyear'

Invoke-Expression $command

S
strangerror, 2020-03-05
@strangerror

$var = $($ht).key1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question