invoke-command

Powershell: How to pass parameter with invoke-command and -filepath remotely?

怎甘沉沦 提交于 2019-12-11 00:48:08
问题 so there's a lot of similar topics to this I've found, but I can't find anything that correlates with my issue. invoke-command -computername $serverLocation -Credential $cred -filepath "C:\path\script2.ps1" -ArgumentList $configPath I am calling a for a script that is stored on my local machine to run on another server. Everything works as intended except for passing the "configPath" variable. This is how I initiate the script - . .\script1.ps1 -serverLocation 'serverNameHere' -username

PowerShell: Start-Job -scriptblock Multi line scriptblocks?

不羁的心 提交于 2019-12-10 21:03:37
问题 Hoping someone can help me to figure out if this is possible. I have a 20 ish lines that scan a log file in a while loop. I need this to happen in parallel with the rest of the script. The log scanning loop is passing the entries into SQLite and other scripts need to act on this information - hence wanting to run them in parallel. If i use the Job-Start command then it seems the -SciptBlock function will only accept one piped line of commands. I have too many commands to want to pipe so i

Character-encoding problem with string literal in source code

懵懂的女人 提交于 2019-12-10 11:34:24
问题 $logstring = Invoke-Command -ComputerName $filesServer -ScriptBlock { param( $logstring, $grp ) $Klassenbuchordner = "KB " + $grp.Gruppe $Gruppenordner = $grp.Gruppe $share = $grp.Gruppe $path = "D:\Gruppen\$Gruppenordner" if ((Test-Path D:\Dozenten\01_Klassenbücher\$Klassenbuchordner) -eq $true) {$logstring += "Verzeichnis für Klassenbücher existiert bereits"} else { mkdir D:\Dozenten\01_Klassenbücher\$Klassenbuchordner $logstring += "Klassenbuchordner wurde erstellt!" }} -ArgumentList

Character-encoding problem with string literal in source code

时间秒杀一切 提交于 2019-12-08 19:08:36
$logstring = Invoke-Command -ComputerName $filesServer -ScriptBlock { param( $logstring, $grp ) $Klassenbuchordner = "KB " + $grp.Gruppe $Gruppenordner = $grp.Gruppe $share = $grp.Gruppe $path = "D:\Gruppen\$Gruppenordner" if ((Test-Path D:\Dozenten\01_Klassenbücher\$Klassenbuchordner) -eq $true) {$logstring += "Verzeichnis für Klassenbücher existiert bereits"} else { mkdir D:\Dozenten\01_Klassenbücher\$Klassenbuchordner $logstring += "Klassenbuchordner wurde erstellt!" }} -ArgumentList $logstring, $grp My goal is to test the existence of a directory and create it on demand. The problem is

Run Command as administrator in PowerShell script. UAC

一个人想着一个人 提交于 2019-12-05 17:22:33
问题 OK here is my issue: I am trying to run a script remotely on a server. I am an administrator on both boxes, firewall exceptions are in place, remote admin is enabled, and everything else looks good that i can see. invoke-command -ComputerName $ComputerName -ScriptBlock ` { cd C:\Windows\System32\inetsrv\; ./appcmd.exe ADD vdir /app.name:<SiteName>/ /path:/<VDir Name> /physicalPath:<Path to files> } I keep getting the following error in return ERROR ( hresult:80070005, message:Failed to commit

Run Command as administrator in PowerShell script. UAC

青春壹個敷衍的年華 提交于 2019-12-04 02:17:44
OK here is my issue: I am trying to run a script remotely on a server. I am an administrator on both boxes, firewall exceptions are in place, remote admin is enabled, and everything else looks good that i can see. invoke-command -ComputerName $ComputerName -ScriptBlock ` { cd C:\Windows\System32\inetsrv\; ./appcmd.exe ADD vdir /app.name:<SiteName>/ /path:/<VDir Name> /physicalPath:<Path to files> } I keep getting the following error in return ERROR ( hresult:80070005, message:Failed to commit configuration changes. Access is denied. The server it is trying to run on is a server 2k8 R2 box and

OutOfMemory Exception on remote execution using Powershell Invoke-Command

删除回忆录丶 提交于 2019-12-04 00:32:24
问题 I am trying to execute an exe on a remote computer using invoke-command. Executing the exe on the remote machine after logging into the machine using remote desktop takes 1GB of memory and executes to completion after a minute. Whereas when I execute the same exe using Invoke-Command on the same machine, the process returns an OutOfMemoryException and ends suddenly. My invoke command is as simple as Invoke-Command -Session $someSessionVariable -ScriptBlock {Invoke-Expression "abc.exe --arg

Powershell Invoke-RestMethod over HTTPS

心不动则不痛 提交于 2019-12-03 10:30:08
I'm trying to communicate with a service over powershell but I am failing miserably. I suspect it is the certificate and I have googled for the answer and found two options, none of which worked for me. I have also tried to combine the two unsuccessfully. Option 1: add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]:

Running Powershell script remotely through Java

天涯浪子 提交于 2019-12-02 05:46:57
问题 I am able to run the below powershell command through Powershell itself, invoke-command -ComputerName "compName" -filepath "c:\script.ps1" -credential "admin" but when I try running that through Java, I get an error. Sounds like "Invoke-command" is not recognized as a program to be run though Java. If this is the case, is there any other solution? Process p = new ProcessBuilder() .inheritIO() .command("invoke-command", "-computername", "compName", "-filepath", "C:\\script.ps1").start(); The

Invoke-Command in a background job

霸气de小男生 提交于 2019-12-02 03:39:39
问题 I have a powershell 2.0 script which should run a command on several servers and process the output. I want to run the command and the processing for each server in a background job. The comand works without any problems and terminates within half a second or less: Invoke-Command -ComputerName $client -ScriptBlock { #do some stuff } But when I run this in a background job, the job doesn't terminate: Start-Job { Invoke-Command -ComputerName $client -ScriptBlock { #do some stuff } } Has someone