powershell

Powershell -replace giving strange behaviour

五迷三道 提交于 2021-02-08 04:56:55
问题 This is driving me nuts! Would appreciate any pointers as to what is going on, please! $alpha = 'aaa.bbb.$connection.ccc.ddd' $s = [regex]::match($alpha,"\$.+?(?=\.)").Value "Alpha is: $alpha" "Matched chunk is: $s" $newChunk = "'" + $s + "'" "New chunk is: $newChunk" $beta = $alpha -replace $s,$newChunk "Beta is: $beta" This produces the following output: Alpha is: aaa.bbb.$connection.ccc.ddd Matched chunk is: $connection New chunk is: '$connection' Beta is: aaa.bbb.$connection.ccc.ddd I am

Powershell wait for dotnet run to launch application on some port

别来无恙 提交于 2021-02-08 04:42:05
问题 I'm writing a script that is supposed to run two dotnet application one after the other. One on port 5000 the second one on port 5001 according to their launchSettings.json So far this is the script that runs the applications: $app1ProjectFolder = '../src/App1' $app2ProjectFolder = '../src/App2' Write-Host "STARTING APP1" -foreground Green Push-Location $app1ProjectFolder $dotnetRunCommandApp1 = 'run' $app1Process = Start-Process dotnet -ArgumentList $dotnetRunCommandApp1 -PassThru Pop

Powershell wait for dotnet run to launch application on some port

放肆的年华 提交于 2021-02-08 04:41:11
问题 I'm writing a script that is supposed to run two dotnet application one after the other. One on port 5000 the second one on port 5001 according to their launchSettings.json So far this is the script that runs the applications: $app1ProjectFolder = '../src/App1' $app2ProjectFolder = '../src/App2' Write-Host "STARTING APP1" -foreground Green Push-Location $app1ProjectFolder $dotnetRunCommandApp1 = 'run' $app1Process = Start-Process dotnet -ArgumentList $dotnetRunCommandApp1 -PassThru Pop

Adding elements to a form from another runspace

僤鯓⒐⒋嵵緔 提交于 2021-02-08 04:08:09
问题 I have a form in which as soon as ready several elements will be added (for example, a list). It may take some time to add them (from fractions of a second to several minutes). Therefore, I want to add processing to a separate thread (child). The number of elements is not known in advance (for example, how many files are in the folder), so they are created in the child stream. When the processing in the child stream ends, I want to display these elements on the main form (before that the form

Powershell - How to search for Whole Words (or) Exact Matches

梦想的初衷 提交于 2021-02-08 04:01:02
问题 this is my requirement. I need to find if a certain CSS classes is referenced in my Solution which has over 120 aspx pages. This is the command that we wrote gci . -include *.aspx -recurse | select-string -pattern ".rtop" -caseSensitive >> D:\CSSResult.txt However, this matches even words with rtop in middle. That is, if I have a variable named as dirtopy, it comes in the result list. I do not want that. I want it in the result only if an exact match of .rtop is found. How do I do it? Any

Powershell - How to search for Whole Words (or) Exact Matches

谁都会走 提交于 2021-02-08 04:00:35
问题 this is my requirement. I need to find if a certain CSS classes is referenced in my Solution which has over 120 aspx pages. This is the command that we wrote gci . -include *.aspx -recurse | select-string -pattern ".rtop" -caseSensitive >> D:\CSSResult.txt However, this matches even words with rtop in middle. That is, if I have a variable named as dirtopy, it comes in the result list. I do not want that. I want it in the result only if an exact match of .rtop is found. How do I do it? Any

Hide Write-Host outputs

爷,独闯天下 提交于 2021-02-08 04:00:31
问题 I am editing a script which I need to convert to exe. It has a few Write-Host outputs of the status of the script when running. This causing the exe of the script to show up dialog boxes to the user forcing them to click OK 3 or 4 times before the script finishes. I'd like to keep the Write-Host output but just hide them (the dialog boxes) when the end user executes it from the exe. Is this possible? I have looked into [void] which the code doesn't like. The only other way I can get to work

test batch statements directly in powershell without wrapping the call in a batch file

谁都会走 提交于 2021-02-08 03:59:54
问题 I am writing a batch file to automate a task using vscode where I get a powershell as my default shell. The line if not exist build (md build) produces errors in powershell. When I pack the same line into a batch file called test.bat I can call ./test.bat and get the expected behaviour. Is there a way to test my batch statements directly in the powershell? 回答1: In powershell use Test-Path : If(!(Test-Path ".\build")){md ".\build"} Or another way.. Cmd /c "your statement" Get error code in

How to correctly send json data via Net.WebRequest - PowerShell

两盒软妹~` 提交于 2021-02-08 03:43:20
问题 I am working on a powershell script to post json data to a REST interface and am getting (400) Bad Request on each time. I am new to this, and am unclear as to if/how I should be encoding the data. I know I need to set the contenttype to application/json, but is the encoding choice I am using what is causing my problem, and if so what should I be using? $cred = New-Object System.Net.NetworkCredential -ArgumentList $authUser,$authPass $url = 'http://localhost:8080/alfresco/service/api/people'

Passing arguments as array to PowerShell function

一笑奈何 提交于 2021-02-08 03:10:23
问题 I'm trying to figure out how I can pass multiple strings as an array to a powershell function. function ArrayCount([string[]] $args) { Write-Host $args.Count } ArrayCount "1" "2" "3" ArrayCount "1","2","3" ArrayCount @("1","2","3") Prints 2 0 0 How can I pass an array with 3 values to the ArrayCount function? Why is the Count zero for some of the invocations? 回答1: In PowerShell, $args is a automatic variable that refers to unnamed arguments. Just change your parameter name: function