powershell-remoting

How do I include a locally defined function when using PowerShell's Invoke-Command for remoting?

爷,独闯天下 提交于 2019-11-27 07:26:16
I feel like I'm missing something that should be obvious, but I just can't figure out how to do this. I have a ps1 script that has a function defined in it. It calls the function and then tries using it remotely: function foo { Param([string]$x) Write-Output $x } foo "Hi!" Invoke-Command -ScriptBlock { foo "Bye!" } -ComputerName someserver.example.com -Credential someuser@example.com This short example script prints "Hi!" and then crashes saying "The term 'foo' is not recognized as the name of a cmdlet, function, script file, or operable program." I understand that the function is not defined

How do I host a Powershell script or app so it's accessible via WSManConnectionInfo? (like Office 365)

Deadly 提交于 2019-11-27 01:34:44
问题 The only ways I know to connect to a remote runspace include the following parameters WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "localhost", 80, "/Powershell", "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential); or WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "localhost", 5985, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.Powershell", credential); How do I set up my own custom Powershell object so I can

Running remote GUI app in Powershell

拈花ヽ惹草 提交于 2019-11-27 01:08:09
问题 We have a custom comonent that wraps some of the functionality of powershell so it can be used frim BizTalk 2006. For most operations (checking a file path, copy or move a file) this works fine. However we have the need to fire up a GUI app remotely to do some processing. The component itself handles the connection to the remote box, all we have to do is set some parameters and then tell it to execute a command Start-Process -FilePath "path to exe" -ArgumentList "arguments for exe"

Powershell remoting with ip-address as target

亡梦爱人 提交于 2019-11-26 19:45:15
I successfully enabled PSRemoting on my Server 2008 R2. I'm able to do a remote-pssession from within the same network using the hostname as target. I'm failing when I try to use the IP-Address as target from any computer (within the network or from another network (for example via VPN)). I want to be able to use remoting through my VPN connection where I have to use the IP-Address since the hostname can't be resolved. I don't want to add names into my hosts-file because there are a few other servers at our clients' that have the same dns-name and I don't want to remove and insert the name-ip

How do I include a locally defined function when using PowerShell's Invoke-Command for remoting?

一曲冷凌霜 提交于 2019-11-26 17:39:23
问题 I feel like I'm missing something that should be obvious, but I just can't figure out how to do this. I have a ps1 script that has a function defined in it. It calls the function and then tries using it remotely: function foo { Param([string]$x) Write-Output $x } foo "Hi!" Invoke-Command -ScriptBlock { foo "Bye!" } -ComputerName someserver.example.com -Credential someuser@example.com This short example script prints "Hi!" and then crashes saying "The term 'foo' is not recognized as the name

Using PowerShell credentials without being prompted for a password

北战南征 提交于 2019-11-26 00:27:11
问题 I\'d like to restart a remote computer that belongs to a domain. I have an administrator account but I don\'t know how to use it from powershell. I know that there is a Restart-Computer cmdlet and that I can pass credential but if my domain is for instance mydomain , my username is myuser and my password is mypassword what\'s the right syntax to use it? I need to schedule the reboot so I don\'t have to type the password. 回答1: The problem with Get-Credential is that it will always prompt for a

How do I pass a local variable to a remote `Invoke-Command`?

笑着哭i 提交于 2019-11-26 00:26:31
问题 I\'m trying to retrieve the hash of a file located on remote server using Invoke-Command . It works fine when I give the full path as below: Invoke-Command -ComputerName winserver -ScriptBlock { Get-FileHash -Path E:\\test\\testfile.zip -Algorithm SHA1 } But I need to pass the file name via a variable as below: Invoke-Command -ComputerName winserver -ScriptBlock { Get-FileHash -Path \"E:\\test\\$dest.zip\" -Algorithm SHA1 } How do I access this variable in the scriptblock of a remote session?