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
How do I get the localhost name in PowerShell?
How do I get the localhost (machine) name in PowerShell? I am using PowerShell 1.0. 10 Answers 10
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
How to format a DateTime in PowerShell
I can format the Get-Date cmdlet no problem like this: $date = Get-Date -format “yyyyMMdd” But once I’ve got a date in a variable, how do I format it? The statement below $dateStr = $date -format “yyyMMdd” returns this error: “You must provide a value expression on the right-hand side of the ‘-f’ operator” 12 … Read more