To encrypt credential which works on different computer(s), you need to generate the key and the encrypted password file.
After you have both key and encrypted file, you could run powershell using that credential generated.
Here is the reference which I referred on.
Creating AES key with random data and export to file:
$KeyFile = "\\Machine1\SharedPath\AES.key"
$Key = New-Object Byte[] 16 # You can use 16, 24, or 32 for AES
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
$Key | out-file $KeyFile
Creating SecureString object
$PasswordFile = "\\Machine1\SharedPath\Password.txt"
$KeyFile = "\\Machine1\SharedPath\AES.key"
$Key = Get-Content $KeyFile
$Password = "P@ssword1" | ConvertTo-SecureString -AsPlainText -Force
$Password | ConvertFrom-SecureString -key $Key | Out-File $PasswordFile
Creating PSCredential object
$User = "MyUserName"
$PasswordFile = "\\Machine1\SharedPath\Password.txt"
$KeyFile = "\\Machine1\SharedPath\AES.key"
$key = Get-Content $KeyFile
$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential `
-ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key)
Example of how to use PSCredential to map network drive:
New-PSDrive -Name P -PSProvider FileSystem -Root $UNC_PATH -Credential $MyCredential -Persist
* Keep the key file somewhere safe, because it is the key that could encrypt/decrypt the password file.