Questions tagged [powershell-2.0]

For topics and problems related specifically to Windows PowerShell 2.0. PowerShell 2.0 shipped with the releases of Windows 7 and Windows Server 2008 R2. For general PowerShell topics, use the `PowerShell` tag.

For general PowerShell information see the tag wiki.

Description of PowerShell-v2.0

Windows PowerShell 2.0 shipped with the releases of Windows 7 and Windows Server 2008 R2. PowerShell 2.0 is available as a download for Windows XP, Windows Vista, Server 2003, Server 2003 R2 and Server 2008.

The major new features in PowerShell 2.0 are:

  • - WinRM / WS-Management based remote administration.
  • - script/binary packaging similar to Perl packages.
  • - integrated script editor and debugging. Adds support for Unicode in the shell.
  • Advanced Functions - provides script functions with cmdlet-style parsing features as well as help via specially formatted comments.
  • Transactions - registry operations support transactional semantics on operating systems that provide the underlying support.
4428 questions
1075
votes
10 answers

How do you comment out code in PowerShell?

How do you comment out code in PowerShell (1.0 or 2.0)?
labyrinth
  • 13,397
  • 7
  • 35
  • 44
686
votes
14 answers

What's the best way to determine the location of the current PowerShell script?

Whenever I need to reference a common module or script, I like to use paths relative to the current script file. That way, my script can always find other scripts in the library. So, what is the best, standard way of determining the directory of the…
Aaron Jensen
  • 25,861
  • 15
  • 82
  • 91
323
votes
10 answers

Recursive file search using PowerShell

I am searching for a file in all the folders. Copyforbuild.bat is available in many places, and I would like to search recursively. $File = "V:\Myfolder\**\*.CopyForbuild.bat" How can I do it in PowerShell?
Samselvaprabu
  • 16,830
  • 32
  • 144
  • 230
298
votes
17 answers

How do I get only directories using Get-ChildItem?

I'm using PowerShell 2.0 and I want to pipe out all the subdirectories of a certain path. The following command outputs all files and directories, but I can't figure out how to filter out the files. Get-ChildItem c:\mypath -Recurse I've tried using…
Peter Hull
  • 6,683
  • 4
  • 39
  • 48
236
votes
20 answers

How to get an MD5 checksum in PowerShell

I would like to calculate an MD5 checksum of some content. How do I do this in PowerShell?
Luke101
  • 63,072
  • 85
  • 231
  • 359
227
votes
11 answers

Delete files older than 15 days using PowerShell

I would like to delete only the files that were created more than 15 days ago in a particular folder. How could I do this using PowerShell?
user2470170
  • 2,320
  • 2
  • 13
  • 8
216
votes
22 answers

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…
Samselvaprabu
  • 16,830
  • 32
  • 144
  • 230
213
votes
6 answers

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?
jrara
  • 16,239
  • 33
  • 89
  • 120
212
votes
15 answers

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,…
Gagan
  • 5,416
  • 13
  • 58
  • 86
200
votes
14 answers

Why is my locally-created script not allowed to run under the RemoteSigned execution policy?

Since this question continues to attract responses that are either refuted by the question body or don't address the actual problem, please read this simple summary of what you need to know: This is not a "Why won't my default installation of…
Lance U. Matthews
  • 15,725
  • 6
  • 48
  • 68
195
votes
32 answers

How to get all groups that a user is a member of?

PowerShell's Get-ADGroupMember cmdlet returns members of a specific group. Is there a cmdlet or property to get all the groups that a particular user is a member of?
Primoz
  • 4,079
  • 17
  • 56
  • 67
180
votes
6 answers

When should I use Write-Error vs. Throw? Terminating vs. non-terminating errors

Looking at a Get-WebFile script over on PoshCode, http://poshcode.org/3226, I noticed this strange-to-me contraption: $URL_Format_Error = [string]"..." Write-Error $URL_Format_Error return What is the reason for this as opposed to the…
Bill Barry
  • 3,423
  • 2
  • 24
  • 22
180
votes
34 answers

How to find the Windows version from the PowerShell command line

How do I find which Windows version I'm using? I'm using PowerShell 2.0 and tried: PS C:\> ver The term 'ver' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was…
jrara
  • 16,239
  • 33
  • 89
  • 120
178
votes
34 answers

Can't install nuget package because of "Failed to initialize the PowerShell host"

All of a sudden, I am getting this error when upgrading Nuget packages. None of the fixes that I have come across work. I am using Visual Studio 2013. 'Newtonsoft.Json 6.0.3' already installed. Adding 'Newtonsoft.Json 6.0.3' to…
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
158
votes
6 answers

Executing an EXE file using a PowerShell script

I'm trying to execute an EXE file using a PowerShell script. If I use the command line it works without a problem (first I supply the name of the executable and series of parameters to invoke it): "C:\Program Files\Automated QA\TestExecute…
Eden
  • 3,696
  • 2
  • 24
  • 24
1
2 3
99 100