Assuming that I have established previously in the code the get-game function and have already created C:\\Stock_Market\\$Username.ps1 and this file is in the same C:\\Stock_Market folder why can the system not find $Username.ps1?
And how can I call the commands from $Username.ps1 to run in this file?
function Log-In {
Clear-Host
$Username = Read-Host "Username"
$Password = Read-Host "Password"
$filepath = "C:\Stock_Market\$Username.ps1"
If (Test-Path $filepath) {
./$Username.ps1
}
Else {
Write-Host "$Username does not exist"
}
# Logging in
if ($Password -eq $realpass) {
get-game
}
Else {
Write-Host "Wrong Password!"
pause
Clear-Host
Log-In
}
}
For this to work you need to use the ampersand in front of the script name, this calls the string as a command and not as a cmdlet or a string.
It's known as the call operator.
Refer to SS64 Call Operator for more info and syntax.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.