Nov 01 2022 12:51 AM
Hi
How do I save an input given by me to a variable?
For example, when I run a script, which contains the Test-Path command, the Terminal window asks me to insert a path.
How do I save this path to a variable?
Thanks
Bye
Nov 02 2022 02:20 PM
Nov 06 2022 05:14 AM
Hello! @balubeto
You can add a variable to your code by using a dollar sign and then a name for the variable, this will then be followed by an equals sign and the value of the variable.
See an example below
$PathVariable = "C:\Users\User1\Temp\"
Test-Path -Path $PathVariable
You could also make the script more interactive by letting the script ask for input by the user and then saving that input to a variable to then later be used in the script. See example below
$FilePath = Read-Host "Please enter a filepath to test"
Test-Path -Path $FilePath
Did this answer your question? Otherwise please let me know and I'd love to help you further :)
Kind Regards
Oliwer Sundgren
Nov 13 2022 09:46 PM
Hi,
You can find all the parameters for test-path in the link below. :thumbs_up::thumbs_up::thumbs_up:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-path?view=p...