powershell

Powershell Find-Package command doesn't work with nuget v3 package source

坚强是说给别人听的谎言 提交于 2021-02-08 19:23:27
问题 As the title says I cannot use the Find-Package command with the nuget v3 url: https://api.nuget.org/v3/index.json If I run the command: Find-Package nuget.versioning -Source https://api.nuget.org/v3/index.json I get an error that no match was found. Changing the command to: Find-Package nuget.versioning -Source https://www.nuget.org/api/v2 Works fine. Do I need to upgrade some software to get this to work? I'm running Powershell version 5 so I'm not sure what steps I need to take to fix this

Format-Table set column width depending on the output buffer width

六眼飞鱼酱① 提交于 2021-02-08 18:27:51
问题 I have a cmdlet that uses Format-Table to output potentially long strings (such as registry paths). I would like to set each column width to the output buffer width divided by the number of columns. Example: function Write-Something { [CmdletBinding()] param() $o = [pscustomobject]@{ a = 'A' * 100; b = 'B' * 100 } $columnWidth = [int]( $PSCmdlet.Host.UI.RawUI.BufferSize.Width / 2 ) $o | Format-Table @{ e = 'a'; width = $columnWidth }, @{ e = 'b'; width = $columnWidth } -wrap } This works

PowerShell - Get Password Expiration for all non Disabled Users in AD

℡╲_俬逩灬. 提交于 2021-02-08 15:46:12
问题 My goal is to create a single object in powershell that shows the AD display name and password expiration date for all non-disabled users. This is relatively easy. However, the date is retrieved in an unreadable format so I convert the date. Creating the two variables that contain the data I want is working. The problem is when I try to combine those two variables I get a single object with two headers as expected but the two columns below are empty. I'm using PowerShell V2 on Win 7 Pro SP1

How do I make Powershell wait until a command is done before continuing?

和自甴很熟 提交于 2021-02-08 15:37:37
问题 My script uninstalls a Windows Store app before installing the newer version. I need to make sure the uninstall is finished before installing, so how can I make sure I've waited long enough? Remove-Appxpackage MyAppName # ~wait here~ Add-Appxpackage .\PathToNewVersion 回答1: You can do this with the Start-Job and Wait-Job cmdlets: Start-Job -Name Job1 -ScriptBlock { Remove-Appxpackage MyAppName } Wait-Job -Name Job1 Add-Appxpackage .\PathToNewVersion Start-Job will start a new job process that

Change date format from “yyyymmdd” to “mm/dd/yyyy”

放肆的年华 提交于 2021-02-08 15:01:28
问题 I've tried a lot of different ways and I can't seem to get it right. Here is the code of what I have tried so far... [String]$dateValue = '20161212' [String]$dateStamp = $dateValue -f (Get-Date) [String]$dateStamp2 = ([datetime]::parseexact($dateValue, "yyyyMMdd", [System.Globalization.CultureInfo]::InvariantCulture)).Date [String]$dateStamp3 = ([datetime]::FromFileTime($dateValue)).ToString('g') Write-Host '$dateStamp = ' $dateStamp Write-Host '$dateStamp2 = ' $dateStamp2 Write-Host '

Invoke-Sqlcmd runs script twice

大兔子大兔子 提交于 2021-02-08 13:59:16
问题 I experienced a very strange issue and can be repeated. Basically, I use invoke-sqlcmd to call a script file by using -inputfile, but if the script file has some execution error (like insert into a table where a column should not be null), the script file will be executed twice. I can see the two executions from profiler as well. Here is the way to reproduce the issue (My environment: Win 8.1 + SQL2014 + PS 5.0) create two tables in a database Use TestDB create table dbo.s (id int identity

Invoke-Sqlcmd runs script twice

我的梦境 提交于 2021-02-08 13:59:14
问题 I experienced a very strange issue and can be repeated. Basically, I use invoke-sqlcmd to call a script file by using -inputfile, but if the script file has some execution error (like insert into a table where a column should not be null), the script file will be executed twice. I can see the two executions from profiler as well. Here is the way to reproduce the issue (My environment: Win 8.1 + SQL2014 + PS 5.0) create two tables in a database Use TestDB create table dbo.s (id int identity

compare-object left or right side only

好久不见. 提交于 2021-02-08 12:59:16
问题 Quick Question Is there a better (i.e. more efficient / more concise) way to do this? compare-object $a $b | ?{$_.SideIndicator -eq '<='} Detail Compare-Object gives paramenters -excludeDifferent and -includeEqual to allow you to amend which results you get. using both gives you an inner join using just -includeEqual gives you a full outer join using just -excludeDifferent is pointless; as by default equal items are excluded, so it will now exclude everything. There are no options for

Disabling Alt+F4 in a Powershell form

落爺英雄遲暮 提交于 2021-02-08 11:57:54
问题 I've written a powershell script which displays a form using System.Windows.Forms . I've already disabled the control box and all other ways that this form can be closed via the mouse. But I can't find a way of preventing the form closing by pressing Alt + F4 . i.e. Code snippet looks like this: [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $objForm = New-Object System.Windows.Forms

Exclude the JSON property only if it exists - Powershell

烈酒焚心 提交于 2021-02-08 11:41:24
问题 I have two different JSONs and I would like to remove streets from the JSON object if only it exists under Address which is an array. I am trying to do this in powershell. I can get my script working and remove the streets but I only want to run the exclude line of command if the address has the streets property. { "Customer": [{ "id": "123" }], "address": [{ "$type": "Home", "name": "Houston", "streets": [{ "name": "Union", "postalCode": "10" }] }, { "$type": "Office", "name": "Hawai",