How to search a string in multiple files and return the names of files in Powershell?
This should give the location of the files that contain your pattern: Get-ChildItem -Recurse | Select-String “dummy” -List | Select Path
This should give the location of the files that contain your pattern: Get-ChildItem -Recurse | Select-String “dummy” -List | Select Path
Remove-Item -Recurse -Force some_dir does indeed work as advertised here. rm -r -fo some_dir are shorthand aliases that work too. As far as I understood it, the -Recurse parameter just doesn’t work correctly when you try deleting a filtered set of files recursively. For killing a single dir and everything below it seems to work … Read more
Use the -wait parameter with Get-Content, which displays lines as they are added to the file. This feature was present in PowerShell v1, but for some reason not documented well in v2. Here is an example Get-Content -Path “C:\scripts\test.txt” -Wait Once you run this, update and save the file and you will see the changes … Read more
When PowerShell sees a command starting with a string it just evaluates the string, that is, it typically echos it to the screen, for example: PS> “Hello World” Hello World If you want PowerShell to interpret the string as a command name then use the call operator (&) like so: PS> & ‘C:\Program Files\IIS\Microsoft Web … Read more
I found it: $env:UserName There is also: $env:UserDomain $env:ComputerName
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.
The very first alias I made once I started customizing my profile in PowerShell was ‘which’. New-Alias which get-command To add this to your profile, type this: “`nNew-Alias which get-command” | add-content $profile The `n at the start of the last line is to ensure it will start as a new line.
I realize this is an old post but I find myself coming back to this thread a lot as it is one of the top search results when searching for this topic. However, I always leave more confused then when I came due to the conflicting information. Ultimately I always have to perform my own … Read more
Parameters in calls to functions in PowerShell (all versions) are space-separated, not comma separated. Also, the parentheses are entirely unneccessary and will cause a parse error in PowerShell 2.0 (or later) if Set-StrictMode -Version 2 or higher is active. Parenthesised arguments are used in .NET methods only. function foo($a, $b, $c) { “a: $a; b: … Read more
Tested as working: #Must be the first statement in your script (not counting comments) param([Int32]$step=30) $iTunes = New-Object -ComObject iTunes.Application if ($iTunes.playerstate -eq 1) { $iTunes.PlayerPosition = $iTunes.PlayerPosition + $step } Call it with powershell.exe -file itunesForward.ps1 -step 15 Multiple parameters syntax (comments are optional, but allowed): <# Script description. Some notes. #> param ( … Read more