You can use environment variables to configure Perforce. Environment variables always begin with $env: in PowerShell.
PowerShell supports a rich set of types, not just strings as in other command shells. Further, because of the way PowerShell parses the right side of assignments, literal strings must be quoted when they appear in that position.
For example, the IP address and port number in the following example must be quoted. Otherwise, PowerShell would try to parse the right side of the assignment as a number. It would parse 192.168 and a number but will then be unable to parse the .0.
PS D:\workspaces\alamimo_ws> $env:P4PORT="192.168.0.2:1666"
Without the quotes, you would have seen this.
Unexpected token '.0' in expression or statement. At line:1 char:22 + $env:P4PORT=192.168.0. <<<< 2:1666
Quotes are also required around the user name in the following example to prevent PowerShell from interpreting it as a command (because of its position on the right side of an assignment).
PS D:\workspaces\alamimo_ws> $env:P4USER="alamimo"
Without the quotes, you would have seen this.
The term 'alamimo' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again. At line:1 char:19 + $env:P4USER=alamimo <<<<
Note, you do not need special quoting when using p4 set because PowerShell passes the arguments as string literals to the p4 command.
PS D:\workspaces\alamimo_ws> p4 set P4CONFIG=P4CONFIG
Works as it does in the XP command interpreter (cmd.exe).
To learn more about how PowerShell parses commands, enter the following at the PowerShell prompt
PS D:\workspaces\alamimo_ws> help about_parsing
To learn more about environment variables, enter the following at the PowerShell prompt
PS D:\workspaces\alamimo_ws> help about_environment_variable