powershell-ise

PowerShell ISE throws an error on git checkout

◇◆丶佛笑我妖孽 提交于 2019-11-28 00:53:58
In PowerShell, git checkout runs without any error message. In the ISE, while git checkout stills works, the ISE gives an error message. > git checkout master Your branch is ahead of 'origin/master' by 3 commits. (use "git push" to publish your local commits) git : Switched to branch 'master' At line:1 char:1 + git checkout master + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Switched to branch 'master':String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError This isn't a major problem, because git checkout still works. It's annoying, though, so I'd like to know why the

Read file line by line in PowerShell

谁说胖子不能爱 提交于 2019-11-27 11:52:28
I want to read a file line by line in PowerShell. Specifically, I want to loop through the file, store each line in a variable in the loop, and do some processing on the line. I know the Bash equivalent: while read line do if [[ $line =~ $regex ]]; then # work here fi done < file.txt Not much documentation on PowerShell loops. Mathias R. Jessen Not much documentation on PowerShell loops. Documentation on loops in PowerShell is plentiful, and you might want to check out the following help topics: about_For , about_ForEach , about_Do , about_While . foreach($line in Get-Content .\file.txt) { if(

Reload the path in PowerShell

风格不统一 提交于 2019-11-27 10:35:11
If I have an instance of PowerShell ISE running and I install something that modifies the PATH or I modify it in any way outside of PowerShell then I need to restart PowerShell for it to see the updated PATH variable. Is there a way to reload the path from within PowerShell without restarting it? mpen Just to bring Rob's comment to light: $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") Try getting the machine path and assigning it to the session's path. $env:Path = [System.Environment]:

Passing a variable to a powershell script via command line

依然范特西╮ 提交于 2019-11-27 05:23:58
问题 I am new to powershell, and trying to teach myself the basics. I need to write a ps script to parse a file, which has not been too difficult. Now I want to change it to pass a variable to the script. that variable will be the parsing string. Now, the variable will always be 1 word, and not a set of words or multiple words. This seems uber simple yet is posing a problem for me. Here is my simple code: $a = Read-Host Write-Host $a When I run the script from my command line the variable passing

Create directory if it does not exist

拈花ヽ惹草 提交于 2019-11-26 23:55:03
问题 I am writing a PowerShell script to create several directories if they do not exist. The filesystem looks similar to this D:\ D:\TopDirec\SubDirec\Project1\Revision1\Reports\ D:\TopDirec\SubDirec\Project2\Revision1\ D:\TopDirec\SubDirec\Project3\Revision1\ Each project folder has multiple revisions. Each revision folder needs a Reports folder. Some of the "revisions" folders already contain a Reports folder; however, most do not. I need to write a script that runs daily to create these

Read file line by line in PowerShell

泄露秘密 提交于 2019-11-26 09:29:32
问题 I want to read a file line by line in PowerShell. Specifically, I want to loop through the file, store each line in a variable in the loop, and do some processing on the line. I know the Bash equivalent: while read line do if [[ $line =~ $regex ]]; then # work here fi done < file.txt Not much documentation on PowerShell loops. 回答1: Not much documentation on PowerShell loops. Documentation on loops in PowerShell is plentiful, and you might want to check out the following help topics: about_For