Questions tagged [powershell-4.0]

For topics and problems related specifically to Windows PowerShell 4.0. PowerShell 4.0 shipped with the releases of with Windows 8.1 and Windows 2012 R2. It is available as a download for Windows 7 SP1. For general PowerShell topics, use the `PowerShell` tag.

For general PowerShell information see the tag wiki.

Description of PowerShell-v4.0

Windows PowerShell Microsoft's strategic task automation platform for Windows, and includes a command-line shell and scripting language. PowerShell was designed especially for system administrators.

PowerShell 4.0 ships with Windows 8.1 and Windows 2012 R2 as a built-in package.

Availability

PowerShell 4.0 is also available as a download for Windows 7 SP1. http://www.microsoft.com/en-us/download/details.aspx?id=40855

Notable New Features in 4.0

Resources

A list of fetaures new and changed int Windows PowerShell is available here.

For latest news and development, check out the PowerShell blog

1951 questions
20
votes
4 answers

Copying to the clipboard in PowerShell without a new line

Is there a way to remove a new line from out-clipboard or clip in PowerShell? I'm using this code to copy current path to clipboard: function cl() { (Get-Location).ToString() | clip } And every time I use this, a new line is added to the copied…
IGRACH
  • 3,506
  • 6
  • 33
  • 48
19
votes
1 answer

Running "Git-Clone" from Powershell giving errors even when it seems to work

How do I interpret the errors coming out of this PowerShell script that calls "Git Clone" (actually using GitLab). And can I clone an empty directory and cause it to work without getting errors? $path1 = "d:\GitPath" $path2 =…
NealWalters
  • 17,197
  • 42
  • 141
  • 251
19
votes
6 answers

Convert string to directory object in PowerShell

I read strings line by line from a file (using Get-Content and a foreach loop), I want to convert those strings to directory objects (so that I can access properties like .FullName). How to easily convert from string to directory? With files it is…
D.R.
  • 20,268
  • 21
  • 102
  • 205
19
votes
5 answers

Using Windows Forms Locks up PowerShell ISE minutes after script has terminated

I have an interesting issue here. I'm creating a calendar picker for use when we create accounts. It works fine and is still in progress but I have noticed that when I run the script in powershell ISE, after a few minutes it locks up (I am able to…
DJ Torres
  • 191
  • 1
  • 6
19
votes
1 answer

Difference between Get-Unique and select-object -unique

Using PowerShell, I import csv-data from file via "import-csv" into the object $csvList. This csv-data has a column called Benutzer. When doing something like this: $csvList | %{$_.Benutzer} | select-object -unique there is nothing special: as…
StefG
  • 368
  • 1
  • 2
  • 8
19
votes
7 answers

How do I get PowerShell 4 cmdlets such as Test-NetConnection to work on Windows 7?

The situation. On a Windows 7 SP1 machine, I have updated with Windows6.1-KB2819745-x64-MultiPkg.msu. Furthermore, in PowerShell $PSVersionTable now reports ‘PSVersion 4.0’. At present, my conclusion is that many PowerShell 4 cmdlets such…
Guy Thomas
  • 933
  • 4
  • 14
  • 31
18
votes
5 answers

Zip and Unzip File in Powershell 4

I am using Windows Server 2012 R2 (64 bit). I have powershell version 4 available in it. I am trying to zip and unzip files. When I try Write-Zip command, it throws me following error: Write-Zip : The term 'Write-Zip' is not recognized as the name…
Raji
  • 857
  • 6
  • 18
  • 37
17
votes
1 answer

Powershell concatenate an Environment variable with path

So I have this code: $userprofile=Get-ChildItem Env:USERPROFILE $localpath="$userprofile\some\path" I would expect output of the below from $localpath: c:\users\username\some\path However what I get…
KyferEz
  • 377
  • 1
  • 3
  • 13
17
votes
4 answers

tee with utf-8 encoding

I'm trying to tee a server's output to both the console and a file in Powershell 4. The file is ending up with a UTF-16 encoding, which is incompatible with some other tools I'm using. According to help tee -full: Tee-Object uses Unicode enocding…
Angus
  • 505
  • 3
  • 12
17
votes
3 answers

Setup default date format like yyyy-mm-dd in Powershell?

A simple & short question: How can I setup a default date format in powershell like yyyy-mm-dd ? so any date output will be like this format? or How to setup a date format globally in one script ? Is there a way to output date only without time?…
Root Loop
  • 3,004
  • 9
  • 46
  • 72
16
votes
2 answers

PowerShell: What is the best way to check whether the current user has permission to overwrite a file in PowerShell?

TL;DR At the beginning of my script, I would like to check whether a file (given as a parameter) is overwritable, and quit if the current user does not have permission to do that. (For example, if the user or the group he/she belongs to has been…
Sk8erPeter
  • 6,899
  • 9
  • 48
  • 67
15
votes
3 answers

What is '@{}' meaning in PowerShell

I have line of scripts for review here, I noticed variable declaration with a value: function readConfig { Param([string]$fileName) $config = @{} Get-Content $fileName | Where-Object { $_ -like '*=*' } | ForEach-Object { …
Mari yah
  • 173
  • 1
  • 1
  • 8
15
votes
4 answers

Using Get-ChildItem -Exclude or -Include returns nothing

I have a list in my C: directory that has many files. If I try to run an -Exclude on it, I get no returns. Same with -Include. If I use -Filter, it returns what I expected to get back. Am I not understanding what it should be doing? Here is an…
bradrice
  • 1,655
  • 2
  • 24
  • 44
15
votes
2 answers

How to cat a UTF-8 (no BOM) file properly/globally in PowerShell? (to another file)

Create a file utf8.txt. Ensure the encoding is UTF-8 (no BOM). Set its content to € In cmd.exe: type utf8.txt > out.txt Content of out.txt is € In PowerShell (v4): cat .\utf8.txt > out.txt or type .\utf8.txt > out.txt Out.txt content is € How do I…
Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
15
votes
4 answers

How to exclude non-valued object properties when converting to JSON in Powershell

I have a piece of code that works but I want to know if there is a better way to do it. I could not find anything related so far. Here are the facts: I have an object with n properties. I want to convert this object to JSON using…
Eduard Uta
  • 2,477
  • 5
  • 26
  • 36