Invoke-Command Creating a User Profile

by jaredatkinson at 2013-04-06 12:04:37

I have noticed that using the Invoke-Command Cmdlet establishes a user profile on the remote host for whoever runs the command. Many tools allow to specify that no user profile is to be established (WinRS, PsExec, and runas). Is there an option to not create a profile when it comes to Invoke-Command?

Examples:

WinRS -nop -r:testhost cmd
PsExec -e \testhost cmd
runas /noprofile /netonly /u:user cmd


The command I ran in the test case was as simple as:

Invoke-Command -ScriptBlock {Get-Process} -ComputerName testhost
by coderaven at 2013-04-06 12:33:36
That was a good question, I had never seen that request before. I just know that every system on the companies I work for have a profile for my admin user as I use it to keep tabs on everything.

You can tell a the invoke-command and PSSession cmdlets not to load the profile on the machine by specifying it as a session option.

Invoke-Command -ScriptBlock { Get-Process} -ComputerName testhost -SessionOption (New-PSSessionOption -NoMachineProfie)
Let me know how it goes.
by jaredatkinson at 2013-04-06 12:39:35
[quote="coderaven"]That was a good question, I had never seen that request before. I just know that every system on the companies I work for have a profile for my admin user as I use it to keep tabs on everything.

You can tell a the invoke-command and PSSession cmdlets not to load the profile on the machine by specifying it as a session option.

Invoke-Command -ScriptBlock { Get-Process} -ComputerName testhost -SessionOption (New-PSSessionOption -NoMachineProfie)
Let me know how it goes.[/quote]

That worked exactly how I wanted! Thank You.
by i255d at 2013-04-10 14:29:24
I get this error:

New-PSSessionOption : A parameter cannot be found that matches parameter name
‘NoMachineProfie’.
At line:1 char:106
+ … SSessionOption -NoMachineProfie)
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:slight_smile: [New-PSSessionOption], Parame
terBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comman
ds.NewPSSessionOptionCommand
by coderaven at 2013-04-10 15:20:41
Looks like you misspelled profile. A common mistake I always make.

[quote="i255d"]I get this error:

New-PSSessionOption : A parameter cannot be found that matches parameter name
‘NoMachineProfie’.
At line:1 char:106
+ … SSessionOption -NoMachineProfie)
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:slight_smile: [New-PSSessionOption], Parame
terBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comman
ds.NewPSSessionOptionCommand[/quote]
by i255d at 2013-04-10 21:29:17
Ha! Yes…

Invoke-Command -ScriptBlock { Get-Process} -ComputerName BigServerAAA -SessionOption (New-PSSessionOption -NoMachineProfile)