powershell-remoting

How to run a command against multiple servers simultaneously in Powershell

99封情书 提交于 2019-12-02 04:28:42
问题 I am looking for a way to restart three services on multiple servers simultaneously. I know how to restart services against a list of servers by using a loop but as I have many servers it would take a long time to wait for each service on each server to restart in a sequential order. Is there a way to send restart service command to all servers at once instead of waiting for each server? 回答1: You could try to work with jobs. Jobs are run in the background and you have to retrieve them with

Powershell - Run a script located at a remote machine which inturn access files from a network share

梦想与她 提交于 2019-12-02 04:19:53
I'm trying to execute a powershell script located at a remote machine using the below command and it works great invoke-command (powershell c:\install\install.ps1) -computername box1 -credential (get-credential) The above script in-turn copies files from a network share (using robocopy) - It fails complaining the location doesn't exist. Found out it was due to permission issue. It works when I explicitly mentioned in the script to use the following credentials for the share net use \share1\files password /user:username Is there a way to pass in the same credentials used to run the script to be

Azure Custom Script Extension. Execute script as another user

匆匆过客 提交于 2019-12-02 02:36:11
I'm using command1.ps1 script to install Azure Custom Script Extension on the target VM and execute command2.ps1. command2.ps1 is supposed to run a script (that is inside ScriptBlock) as domain administrator (hence -Credential $Credentials ). When I run command2.ps1 manually and input $domainAdminName and $domainAdminPassword it works, but when running it through command1.ps1 it doesn't work. Maybe the problem is cause by Azure Custom Script Extension running command2.ps1 as System account? Please, help me make the script work. command1.ps1: param ( [Parameter(Mandatory)] [String]

Invoke-command -ArgumentList parameter syntax

ぃ、小莉子 提交于 2019-12-01 18:23:02
I'm trying to add multiple csv-imported lists to a remote executed PS script. It works fine when I pass only one list using the following command: Invoke-Command -filepath $createSAPSPath -ConnectionUri $uri -Credential $credential -ArgumentList (,$accountsList) What would be the correct syntax for multiple list objects? I've tried: Invoke-Command -filepath $createSAPSPath -ConnectionUri $uri -Credential $credential -ArgumentList (,$accountsList),(,$groupsList) But it doesn't seem to work... Thanks, Glenn You have to realize why you need unary comma in the first situation, to understand why

Creating a registry key with path components via PowerShell

本秂侑毒 提交于 2019-12-01 16:50:43
For a legacy application, I need to create a registry key with a name in the format c:/foo/bar/baz . (Note: forward slashes, not backslashes.) To be clear: that is a single key's name, with forward slashes, that otherwise looks like a Windows path. Because I need to script this against lots of servers, PowerShell seems like a great option. The problem is that I cannot figure out how to create a key in that format via PowerShell. New-Item -Path HKLM:\SOFTWARE\Some\Key -Name 'c:/foo/bar/baz' errors out with PowerShell thinking I'm using / as a path separator and failing to find the path HKLM:

How can I add color to the machine name in the prompt of a PowerShell Remoting session?

筅森魡賤 提交于 2019-12-01 15:59:10
问题 To make it more obvious when I'm remoted to a live/production server, I thought it'd be handy to be able to colour the machine name I'm connected to when using remote PowerShell sessions. However, I can't see a way to do this... The server name prefix seems to be independent of the Prompt function, and even if I could use that, I'm not sure how I could define a new Prompt only for the duration of the session. Is there a way to customise this? Note: I don't want to color all server names the

Creating a registry key with path components via PowerShell

我们两清 提交于 2019-12-01 15:48:29
问题 For a legacy application, I need to create a registry key with a name in the format c:/foo/bar/baz . (Note: forward slashes, not backslashes.) To be clear: that is a single key's name, with forward slashes, that otherwise looks like a Windows path. Because I need to script this against lots of servers, PowerShell seems like a great option. The problem is that I cannot figure out how to create a key in that format via PowerShell. New-Item -Path HKLM:\SOFTWARE\Some\Key -Name 'c:/foo/bar/baz'

PowerShell remoting: Controlling what edition is being targeted (PowerShell Core or Windows PowerShell); the state of cross-platform remoting

跟風遠走 提交于 2019-12-01 13:38:48
This self-answered question, which focuses on Windows [1] , addresses the following aspects: Now that there are two PowerShell editions - the legacy, Windows-only Windows PowerShell and the cross-platform PowerShell Core , both may be installed on a given Windows machine: How can I tell which PowerShell edition will execute remote commands , such as via Invoke-Command -ComputerName ? How can I target a specific edition , both ad hoc and persistently , through configuration? Note: For an edition to be targetable via remoting on a given machine, it must be set up for remoting : Only Windows

Why does PowerShell class not load a snapin

巧了我就是萌 提交于 2019-12-01 13:38:45
I have this code in which I load a snapin (from MS Dynamics NAV in this case): using (Runspace runspace = RunspaceFactory.CreateRunspace()) { runspace.Open(); using (var ps = PowerShell.Create()) { ps.Runspace = runspace; ps.AddScript("Add-PSSnapin Microsoft.Dynamics.Nav.Management") .AddScript("Get-NAVServerInstance"); //This does not work. Says unknown cmdlet Get-NAVServerInstance //ps.AddCommand("Add-PSSnapin").AddArgument("Microsoft.Dynamics.Nav.Management") // .AddCommand("Get-NAVServerInstance"); var output = ps.Invoke(); } } This code works when I use the AddScript method as shown in

Why does PowerShell class not load a snapin

天大地大妈咪最大 提交于 2019-12-01 10:54:05
问题 I have this code in which I load a snapin (from MS Dynamics NAV in this case): using (Runspace runspace = RunspaceFactory.CreateRunspace()) { runspace.Open(); using (var ps = PowerShell.Create()) { ps.Runspace = runspace; ps.AddScript("Add-PSSnapin Microsoft.Dynamics.Nav.Management") .AddScript("Get-NAVServerInstance"); //This does not work. Says unknown cmdlet Get-NAVServerInstance //ps.AddCommand("Add-PSSnapin").AddArgument("Microsoft.Dynamics.Nav.Management") // .AddCommand("Get