I want to query a server for, say memory
gwmi win32_freephysicalmemory -computername server1 -credential $cred
I know about get-credentials and also constructing an pscredential-object, but i want to first try to query with my current credentials, and if i get unauthorizedexception ill prompt for new credentials with get-credentials. this way i could run the script from either my workstation or some server (i dont use the same creds)
i think i initially need to feed $cred with my current credentials and then change it in the catchblock if it fails, but how do i dump my logged on credentials to an pscreential-object?