powershell-remoting

Powershell Script Running Slowly

别来无恙 提交于 2019-12-04 06:10:15
问题 I'm writing a script to check the version on about 15 remote servers and the script is taking much longer to execute than I would expect. $listServers = @("compName1", "compName2", "compName3", ... "compName15") "" | Out-File C:\temp\javaVersion.txt "" | Out-File C:\temp\javaVersionLog.txt $cred = Get-Credential ForEach ($server in $listServers) { Measure-Command {$javaVersion = Invoke-Command -ComputerName $server -Credential $cred -Authentication Kerberos -ScriptBlock {Get-WmiObject -Class

Gracefully closing a process in a remote Session

安稳与你 提交于 2019-12-04 05:29:29
问题 I'm currently working on a little PowerShell Script to reset a users Outlook Profile on a remote machine. Before the necessary profile stuff can be done I want to check if Outlook is already running on the remote machine and, if it is, stop it gracefully. I don't want to kill the process so it can do its necessary clean-up and syncing. When I connect to the machine with an Administrative User and execute the following commands: Enter-PSSession $remoteMachine $outlookProcess = Get-Process

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

社会主义新天地 提交于 2019-12-04 04:58:32
问题 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

In PowerShell how to copy files from a Remote PSsession to another Windows server

我的未来我决定 提交于 2019-12-04 04:21:31
问题 I am trying to copy a folder from one remote server to another inside a PSSession, it's giving errors like access is denied. I have admin privileges to both of the servers. If I try it without PSSession it works. In remote serverA PS C:\Users\Automation\Documents> [System.Net.Dns]::GetHostName() sql PS C:\Users\Automation\Documents> Copy-Item -Path .\abc.csv -Destination "\\jump\c$" PS C:\Users\Automation\Documents> In remote serverB PS C:\Users\Automation\Documents\sample\SQL Final Scripts>

Invoke-command -ArgumentList parameter syntax

拜拜、爱过 提交于 2019-12-04 03:46:23
问题 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...

Powershell Remoting: using imported module cmdlets in a remote pssession

时间秒杀一切 提交于 2019-12-03 11:49:06
问题 Is there a way to use modules that were imported in a local session in a remote session? I looked at import-pssession, but I don't know how to get the local session. Here's a sample of what I want to do. import-module .\MyModule\MyModule.ps1 $session = new-pssession -computerName RemoteComputer invoke-command -session $session -scriptblock { Use-CmdletFromMyModule } Also, I do not want to import-module in the remote session, as the ps1 files are not on that server. 回答1: I ended up hacking

Enter-PSSession is not working in my Powershell script

烈酒焚心 提交于 2019-12-03 09:22:36
When I run the lines below from a script the file ends up being created on my local machine. $cred = Get-Credential domain\DanTest Enter-PSSession -computerName xsappb01 -credential $cred New-Item -type file c:\temp\blahxsappk02.txt exit-pssession When I run each line individually from the powershell console the remote session is created correctly and the file is created on the remote machine. Any thoughts on why? Is it a timing issue is the script perhaps? Not sure if it is a timing issue. I suspect it's more like Enter-PSSession is invoking something like a nested prompt and your subsequent

how to edit a file in powershell remoting session (powershell)

五迷三道 提交于 2019-12-03 04:45:49
问题 I am connecting to another computer using powershell remoting, really nice. can do lots, but how do I edit a file? PS C:\Users\guutlee> Enter-PSSession -ComputerName appprod [appprod]: PS C:\Users\guutlee\Documents> cd \myapp [appprod]: PS C:\myapp> what can I do to open a file editor on a file on the remote machine? [appprod]: PS C:\myapp> edit app.config so edit "filename" just seems to hang, from powershell.exe or from powershell_ise.exe The only thing I can think of is back out of the

how to edit a file in powershell remoting session (powershell)

妖精的绣舞 提交于 2019-12-02 17:56:48
I am connecting to another computer using powershell remoting, really nice. can do lots, but how do I edit a file? PS C:\Users\guutlee> Enter-PSSession -ComputerName appprod [appprod]: PS C:\Users\guutlee\Documents> cd \myapp [appprod]: PS C:\myapp> what can I do to open a file editor on a file on the remote machine? [appprod]: PS C:\myapp> edit app.config so edit "filename" just seems to hang, from powershell.exe or from powershell_ise.exe The only thing I can think of is back out of the pssession and "start \webprod\c$\inetpub\myapp\web.config", which would open visual studio. [appprod]: PS

Get-Content and foreach in two files

孤街浪徒 提交于 2019-12-02 12:21:00
I have two files. The first with contains hostnames (Computers.txt) and the second one contains SID (SID.txt). I want to use Get-Content and foreach to execute a command on each computer with the corresponding SID to modify registry. Let's take for example PC 1 (first line Computers.txt with first line SID.txt) and PC 2 (second line Computers.txt with second line SID.txt). $Computer = Get-Content D:\Downloads\computers.txt $SID = Get-Content D:\Downloads\SID.txt foreach ($pc in $Computer) { Invoke-Command -ComputerName $pc {New-Item HKEY_USERS:\$SID -Name -Vaue} } Using a foreach -loop doesn't