powershell
Get full path of the files in PowerShell
I need to get all the files including the files present in the subfolders that belong to a particular type. I am doing something like this, using Get-ChildItem: Get-ChildItem “C:\windows\System32” -Recurse | where {$_.extension -eq “.txt”} However, it’s only returning me the files names and not the entire path. 15 Answers 15
How do I output text without a newline in PowerShell?
I want my PowerShell script to print something like this: Enabling feature XYZ……Done The script looks something like this: Write-Output “Enabling feature XYZ…….” Enable-SPFeature… Write-Output “Done” But Write-Output always prints a new-line at the end so my output isn’t on one line. Is there a way to do this? 19 Answers 19
Is there a way to make a PowerShell script work by double clicking a .ps1 file?
I am distributing a PowerShell script to my team. The script is to fetch an IP address from the Vsphere client, make an mstsc connection, and log it in a shared file. The moment they used the script they got to know the IP address of machine. After that, they always tend to use mstsc … Read more
PowerShell: How do I convert an array object to a string in PowerShell?
How can I convert an array object to string? I tried: $a = “This”, “Is”, “a”, “cat” [system.String]::Join(” “, $a) with no luck. What are different possibilities in PowerShell? 6 Answers 6
Call PowerShell script PS1 from another PS1 script inside Powershell ISE
I want call execution for a myScript1.ps1 script inside a second myScript2.ps1 script inside Powershell ISE. The following code inside MyScript2.ps1, works fine from Powershell Administration, but doesn’t work inside PowerShell ISE: #Call myScript1 from myScript2 invoke-expression -Command .\myScript1.ps1 I obtain the following error when I execute MyScript2.ps1 from PowerShell ISE: The term ‘.\myScript1.ps1’ is … Read more
Powershell equivalent of bash ampersand (&) for forking/running background processes
In bash the ampersand (&) can be used to run a command in the background and return interactive control to the user before the command has finished running. Is there an equivalent method of doing this in Powershell? Example of usage in bash: sleep 30 & 8 Answers 8
PowerShell and the -contains operator
Consider the following snippet: “12-18” -Contains “-” You’d think this evaluates to true, but it doesn’t. This will evaluate to false instead. I’m not sure why this happens, but it does. To avoid this, you can use this instead: “12-18”.Contains(“-“) Now the expression will evaluate to true. Why does the first code snippet behave like … Read more
PowerShell equivalent to grep -f
I’m looking for the PowerShell equivalent to grep –file=filename. If you don’t know grep, filename is a text file where each line has a regular expression pattern you want to match. Maybe I’m missing something obvious, but Select-String doesn’t seem to have this option. 9 Answers 9
What’s the difference between “Write-Host”, “Write-Output”, or “[console]::WriteLine”?
There are a number of different ways to output messages. What is the effective difference between outputting something via Write-Host, Write-Output, or [console]::WriteLine? I also notice that if I use: write-host “count=” + $count The + gets included in the output. Why’s that? Shouldn’t the expression be evaluated to produce a single concatenated string before … Read more