Invoke PS session

Hi,

I'm trying to get a poweshell script to run as my privileged account in an enterprise domain below is the power shell script that I'm running. This is just a test script where I'm trying to get-process at the mometn.

Start-Transcript C:\Users\useraccount\Desktop\PSLog.txt
$computer = Read-host "please enter a fully qualified computer name"
Test-WsMan $computer
Invoke-Command -ComputerName $computer -ScriptBlock { Get-Process Powershell > C:\Users\useraccount\Desktop\Process.tx  } -credential [-username]
exit
Read-Host -Prompt "Press Enter to exit"
Stop-Transcript

I'm using the below batch command to run the script.

@ECHO OFF
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"
PAUSE

And below is the Transcript:

**********************
Windows PowerShell Transcript Start
Start time: 20150525160839
Username  : domain\PriviledgedAccount 
Machine  : HostName (Microsoft Windows NT 6.1.7601 Service Pack 1) 
**********************
Transcript started, output file is C:\Users\Useraccount\Desktop\PSLog.txt
please enter a fully qualified computer name: HostName


wsmid           : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.x
                  sd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor   : Microsoft Corporation
ProductVersion  : OS: 0.0.0 SP: 0.0 Stack: 2.0

[HostName] Connecting to remote server failed with the following error messa
ge : Logon failure: unknown user name or bad password. For more information, se
e the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionStateBroken
**********************
Windows PowerShell Transcript End
End time: 20150525160902
**********************

Not sure why this is not authenticating, I'm running the batch file as my PriviledgedAccount by holding Shift, Run as a different user.

I will need this to jump across domains eventually but just want to get this to work in one domain at the moment.
Any advice or hints in regards to why I'm getting the authentication error would be greatly appreciated. 


May 25th, 2015 5:25am

I would suggest that you start by learning PowerShell.  YOucannot paste help text with no understanding andhoe that it will work.

Try learning how to use each command before you try to us it in a script.  THe folloowinglineis noto a command but is copied help test:

Invoke-Command -ComputerName$computer -ScriptBlock { Get-Process Powershell >C:\Users\useraccount\Desktop\Process.tx  } -credential [-username]

No matter how we look at it it makes absolutely no sense.

To get remote prcesses do this:

Get-Process -ComputerName $computer

To remote a command with credentials we would do this:

Invoke-Command -ScriptBlock {dir c:\} -computer $computer -Credentials userdomain\userid


Free Windows Admin Tool Kit Click here and download it now
May 25th, 2015 11:25am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics