I have a c# / powershell problem. Any help will be greatly appreciated.
My c# socket server listens on a port, listens for a TcpClient, creates a NetworkStream, GetBytes from the client, covert those bytes to string, passes that string to RunShell method which executes that string as a power shell command, coverts that string to bytes, sends it off to the client.
The problem is that all the "string" commands executed by the powershell method are not executed the way they are on a regular powershell prompt. for example get-command works fine but get-alias does:
get-alias on regular powershell prompt:
CommandType Name Definition
----------- ---- ----------
Alias ac Add-Content
Alias asnp Add-PSSnapin
Alias clc Clear-Content
get-alias from my c# prompt:
Sending parameters: 'get-alias'...<done
Welcome to power shell server ...
ac
asnp
clc
Best Regards,
sk
cli
My c# socket server listens on a port, listens for a TcpClient, creates a NetworkStream, GetBytes from the client, covert those bytes to string, passes that string to RunShell method which executes that string as a power shell command, coverts that string to bytes, sends it off to the client.
The problem is that all the "string" commands executed by the powershell method are not executed the way they are on a regular powershell prompt. for example get-command works fine but get-alias does:
get-alias on regular powershell prompt:
CommandType Name Definition
----------- ---- ----------
Alias ac Add-Content
Alias asnp Add-PSSnapin
Alias clc Clear-Content
get-alias from my c# prompt:
Sending parameters: 'get-alias'...<done
Welcome to power shell server ...
ac
asnp
clc
Best Regards,
sk
cli