powershell-5.0

How to list VSTS agent pools programmatically from PowerShell?

情到浓时终转凉″ 提交于 2019-12-01 08:43:57
问题 I want to connect to VSTS and get a list of agent pools. I want to enumerate the agent pools and then delete agents on the VSTS server. I can't find any documentation for how to do this in the VSTS API reference. I'm connecting to VSTS fine like this to list projects for example, but how to list agent pools? $User = 'mark.allison@domain.com' $PersonalAccessToken = '{PAT_TOKEN}' $base64authinfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User,

How do I create file hardlink in PowerShell on Windows 10?

假装没事ソ 提交于 2019-12-01 02:45:10
How do I create file hardlink in PowerShell on Windows 10? PSCX has New-Hardlink , but is it still needed on Windows 10? You could always shell out to mklink , but from powershell that requires you prefix the command with cmd /c , which is ugly and hard to remember. New-Item -ItemType HardLink -Name CoverageCount.cs -Value ..\..\OPIAspnet5\Models\CoverageCount.cs The ItemType parameter now includes a type for hardlinks, which I feel is a hidden gem of PowerShell on Windows 10. 来源: https://stackoverflow.com/questions/31863258/how-do-i-create-file-hardlink-in-powershell-on-windows-10

Powershell 5 Get-ChildItem LiteralPath doesn't work with Include anymore

你。 提交于 2019-11-30 19:36:40
Right now I updated to Windows 10 TH2 Build 10586 with PowerShell 5.0.10586.0 Now I got a problem with Get-ChildItem $files = Get-ChildItem -LiteralPath $path -Force -Recurse -Include *.txt This returns ALL files in $path even they are not .txt. This was working before the update. When I change it to $files = Get-ChildItem -Path $path -Force -Recurse -Include *.txt it works again. But that's not what I want. Is this a bug or am I doing something wrong? Personally, I never use -Include or -Exclude anymore. I always pipe through Where-Object . I don't know if the author of -Include and -Exclude

Powershell 5 Get-ChildItem LiteralPath doesn't work with Include anymore

荒凉一梦 提交于 2019-11-30 04:20:52
问题 Right now I updated to Windows 10 TH2 Build 10586 with PowerShell 5.0.10586.0 Now I got a problem with Get-ChildItem $files = Get-ChildItem -LiteralPath $path -Force -Recurse -Include *.txt This returns ALL files in $path even they are not .txt. This was working before the update. When I change it to $files = Get-ChildItem -Path $path -Force -Recurse -Include *.txt it works again. But that's not what I want. Is this a bug or am I doing something wrong? 回答1: Personally, I never use -Include or

Piping ListView items in separate runspace

青春壹個敷衍的年華 提交于 2019-11-29 17:28:55
I have a form written in PowerShell (as it uses PS to run commands over hundreds of servers) but this bit had me stumped for awhile: $listview.Invoke([System.Action[String]]{ Param ( [String]$data ) write-warning "1" $LVitem = ($LVresults.Items | Where { $_.Name -eq "Test Account" }) write-warning "2" $LVitem.Tag.Output += $data + "`n" }, "Testing") It's in a separate runspace that runs an Invoke-Command to a specific server and pipes the output to this code block. Now if I run the Where statement in the main runspace (where the form is created) it works perfectly fine. In the separate

How do I create file hardlink in PowerShell on Windows 10?

对着背影说爱祢 提交于 2019-11-29 17:01:40
问题 How do I create file hardlink in PowerShell on Windows 10? PSCX has New-Hardlink , but is it still needed on Windows 10? You could always shell out to mklink , but from powershell that requires you prefix the command with cmd /c , which is ugly and hard to remember. 回答1: New-Item -ItemType HardLink -Name CoverageCount.cs -Value ..\..\OPIAspnet5\Models\CoverageCount.cs The ItemType parameter now includes a type for hardlinks, which I feel is a hidden gem of PowerShell on Windows 10. 来源: https:

Get error while running Enable-Migrations

混江龙づ霸主 提交于 2019-11-28 23:56:54
I got below error while running Enable-Migrations on my ASP.NET MVC5 project (Powershell v5 & Visual Studio 2015). I have tried to uninstall and re-install EntityFramework (v6.1.3) but no lucky. Does anyone know how to solve it? Type name 'Microsoft.VisualStudio.Shell.Package' is ambiguous, it could be 'Microsoft.VisualStudio.Shell.Package, Microsoft.VisualStudio.Shell.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or 'Microsoft.VisualStudio.Shell.Package, Microsoft.VisualStudio.Shell.11.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. At C:

PowerShell type accelerators: PSObject vs PSCustomObject

北慕城南 提交于 2019-11-28 13:20:02
In PowerShell v3.0 PSCustomObject was introduced. It's like PSObject , but better. Among other improvements (e.g. property order being preserved), creating object from hashtable is simplified: [PSCustomObject]@{one=1; two=2;} Now it seems obvious that this statement: [System.Management.Automation.PSCustomObject]@{one=1; two=2;} would work the same way, because PSCustomObject is an "alias" for full namespace + class name. Instead I get an error: Cannot convert the "System.Collections.Hashtable" value of type "System.Collections.Hashtable" to type "System.Management.Automation.PSCustomObject". I

how to export a class in powershell v5 module

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 07:30:59
I've got a module setup to be like a library for a few other scripts. I can't figure out how to get a class declaration into the script scope calling Import-Module . I tried to arrange Export-Module with a -class argument, like the -function , but there isn't a -class available. Do I just have to declare the class in every script? The setup: holidays.psm1 in ~\documents\windows\powershell\modules\holidays\ active script calls import-module holidays there is another function in holidays.psm1 that returns a class object correctly, but I don't know how to create new members of the class from the

PowerShell 5 and classes - Cannot convert the “X” value of type “X” to type “X”

…衆ロ難τιáo~ 提交于 2019-11-28 02:02:14
I'm trying to use PowerShell's classes that is very handy way of grouping related data together and facing quite tedious to deal with behavior. The simplified scenario: one PS script that defines class and another script that uses that class. Common.ps1 class X { [string] $A } Script1.ps1 . $PSScriptRoot\Common.ps1 [X] $v = New-Object X Everything is good - you can run Script1.ps1 arbitrary amount of times with no issues - until you make any change in Common.ps1 . You will face the following error. Cannot convert the "X" value of type "X" to type "X". At D:\temp\PSIssue\Script1.ps1:3 char:1 +