invoke-command

Invoke a second script with arguments from a script

元气小坏坏 提交于 2020-01-20 12:53:15
问题 I have a script that reads a configuration file that results in a set of name value pairs that I would like to pass as arguments to a function in a second PowerShell script. I do not know what parameters will be placed in this configuration file at design time, so right at the point where I need to invoke this second PowerShell script, I basically just have one variable that has the path to this second script, and a second variable that is an array of arguments to pass to the script

how to parse json response in powershell

荒凉一梦 提交于 2020-01-13 06:52:13
问题 managed to get the JSON data with $R= Invoke-WebRequest -Uri $url -Headers $headers -ContentType "application/json" -Method Get -UseBasicParsing $x = $R.Content | Out-String | ConvertFrom-Json now I've a JSON file like this : { "id": 1000, "name_with_namespace": "myProjectName1", }, { "id": 1001, "name_with_namespace": "myProjectName2", }, { "id": 1002, "name_with_namespace": "myProjectName3", } now I need to extract all the occurence of "name_with_namespace" and "id" where "name_with

PowerShell Invoke-Command using Start-Process is not creating log file

梦想与她 提交于 2020-01-07 04:01:28
问题 I have a command line exe on a remote server which I need to execute remotely (running on the remote server). This exe connects to the DB, and writes a log file. I have enabled WinRM by executing these PowerShell commands: netsh http add iplisten localip {add local ip here} netsh http add iplisten 127.0.0.1 Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force Enable-PSRemoting -Force This works and I was able to test by executing Test-WSMan {computername} I am now trying to execute

Taking input from one PSSession and sending it to another

╄→尐↘猪︶ㄣ 提交于 2019-12-24 19:33:51
问题 Like many others, my background is in Linux with no powershell experience. So this object oriented programming is messing me up. I need to search through VMware Horizon for VMs with users assigned to them, then check if they are disabled in AD. If they are disabled in AD I want to recycle the VM. At the moment I am pulling the SIDs for the users from VMware Horizon, but when I try to use these in an invoke-command against AD I receive the following error "Object reference not set to an

Invoke-Command returning data

亡梦爱人 提交于 2019-12-24 10:31:20
问题 I am working on a script to query remote servers for configuration information and return the data for output to gridview. The issue I am having is the format in which the data is returned. If I do... ((Get-CimInstance -ClassName Win32_Processor).NumberOfLogicalProcessors | Measure-Object).Count ((Get-CimInstance -ClassName Win32_PhysicalMemory).Capacity | Measure-Object -Sum).Sum /1GB in a ps1 and run that on a remote server using Invoke-Command, I get an array back with only numbers like

Powershell Remote Invoke-Command Start-Process App Immediately Closes After Launch

ぐ巨炮叔叔 提交于 2019-12-24 08:31:46
问题 I am working on a script to remotely kill two processes, delete some folders, and launch a service as an application. Eventually this will be deployed to run against multiple servers, but I'm currently testing it against a single server. Everything works great except for the final step which is to launch the remote service (which is being run as an application using the -cl argument due to some compatibility issues with it running as a service). The application launches via the script but

powershell: script to start a program with parameters?

淺唱寂寞╮ 提交于 2019-12-24 00:56:49
问题 When i run the Powershell script below i receive the error below. How do i run programs through powershell with parameters? The script will be a group policy logon. Invoke-Expression : A positional parameter cannot be found that accepts argument '\TBHSERVER\NETLOGON\BGInfo\BGIFILE.bgi /timer:0 /s ilent /nolicprompt '. At X:\Systems\scripts\PowerShell\UpdateDesktopWithBGInfo.ps1:6 char:18 + Invoke-Expression <<<< $logonpath $ArguList + CategoryInfo : InvalidArgument: (:) [Invoke-Expression],

How do I retain ScriptStackTrace in an exception thrown from within an Invoke-Command on a remote computer?

♀尐吖头ヾ 提交于 2019-12-21 10:17:05
问题 I'm writing a Powershell script which executes one of the steps in my build/deploy process, and it needs to run some actions on a remote machine. The script is relatively complex, so if an error occurs during that remote activity I want a detailed stack trace of where in the script the error occurred (over and above the logging that is already produced). The problem arises in that Invoke-Command loses stack trace information when relaying terminating exceptions from a remote machine. If a

Powershell Invoke-RestMethod over HTTPS

十年热恋 提交于 2019-12-21 03:29:09
问题 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,

Using Powershell's Invoke-Command to call a batch file with arguments

北战南征 提交于 2019-12-19 06:03:10
问题 I want to use Powershell in order to call a batch file on remote machines. This batch file has arguments. Here's what I have so far: $script = "\\fileshare\script.cmd" $server = $args[0] $args [string]::join(',',$args[1 .. ($args.count-1)]) Invoke-Command -computername $server {$script + ' ' + $args} After a bit of searching, I found that the Invoke-Command function runs its scriptblock in a whole new process, so you can't put variables in it (they won't get expanded). That's what the