When I run ( open powershell.exe > .\test_cred.ps1) this it sees that the $cred is not set and prompts for credentials. If I run the script a second time in the same powershell console it prompts for the credentials again. If I enter $cred = Get-Credential then run the script it sees that $cred is set and does not prompt. This appears to be a scope issue, where I cannot set a console level variable from a script.
Is there a trick around this? I do not want to use a passwords file or the like.
If you want a script to set variables in the session that ran it, typically you'd add an extra period and space before the script path. This is called "dot sourcing", and is described in the about_Scripts help file.