Passing a variable to a powershell script via command line
Make this in your test.ps1, at the first line param( [string]$a ) Write-Host $a Then you can call it with ./Test.ps1 “Here is your text” Found here (English)
Make this in your test.ps1, at the first line param( [string]$a ) Write-Host $a Then you can call it with ./Test.ps1 “Here is your text” Found here (English)
The Resolve-Path cmdlet has a -Relative parameter that will return a path relative to the current directory: Set-Location C:\MyScript $relativePath = Get-Item Data\Test.txt | Resolve-Path -Relative
Use the command pane. Open the script file in the ISE editor, set the breakpoints (F9). Then in the command pane type a command invoking this script with required parameters. I do not think there is another (built-in) way of doing this in ISE.
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($line -match $regex){ # Work here } } Another idiomatic PowerShell solution to your problem is to pipe the lines of the … Read more
Just to bring Rob’s comment to light: $env:Path = [System.Environment]::GetEnvironmentVariable(“Path”,”Machine”) + “;” + [System.Environment]::GetEnvironmentVariable(“Path”,”User”)
Try the -Force parameter: New-Item -ItemType Directory -Force -Path C:\Path\That\May\Or\May\Not\Exist You can use Test-Path -PathType Container to check first. See the New-Item MSDN help article for more details.