This Advanced Function will look to see if the current user context running a command/script is an Administrator or not. If not, a menu is presented to the user to either continue or enter alternate credentials. The function will either return a credential object of the alternate credential or a string type stating that the current user context will be used.
With that you can use an If statement to check for the alternate credential and use that instead.
$admincheck = Test-IsAdmin
If ( -is [System.Management.Automation.PSCredential])
Get-WMIObject -computername Server1 Win32_OperatingSystem -Credential $admincheck
Get-WMIObject -computername Server1 Win32_OperatingSystem