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?by coderaven at 2013-04-06 12:33:36
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
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.by jaredatkinson at 2013-04-06 12:39:35
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="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.by i255d at 2013-04-10 14:29:24
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.
I get this error:by coderaven at 2013-04-10 15:20:41
New-PSSessionOption : A parameter cannot be found that matches parameter name
‘NoMachineProfie’.
At line:1 char:106
+ … SSessionOption -NoMachineProfie)
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: ( [New-PSSessionOption], Parame
terBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comman
ds.NewPSSessionOptionCommand
Looks like you misspelled profile. A common mistake I always make.by i255d at 2013-04-10 21:29:17
[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: ( [New-PSSessionOption], Parame
terBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comman
ds.NewPSSessionOptionCommand[/quote]
Ha! Yes…Invoke-Command -ScriptBlock { Get-Process} -ComputerName BigServerAAA -SessionOption (New-PSSessionOption -NoMachineProfile)