powershell-5.0

`more.com` returns “Not enough memory.”

早过忘川 提交于 2021-02-07 14:37:49
问题 Environment details: x64 Win7 SP1 Enterprise Windows PowerShell v5.0 Without any profiles loaded, my local powershell sessions are returning Not enough memory. when I try to execute help or man . This occurs whether I'm using the native powershell.exe or conemu. Strangely, I am able to execute any other aliases I've tried, and it doesn't add to the $Error variable, so I have no idea where to start troubleshooting (I've tried -ErrorAction Stop and $ErrorActionPreference = 'Stop' ). As a

`more.com` returns “Not enough memory.”

天大地大妈咪最大 提交于 2021-02-07 14:32:50
问题 Environment details: x64 Win7 SP1 Enterprise Windows PowerShell v5.0 Without any profiles loaded, my local powershell sessions are returning Not enough memory. when I try to execute help or man . This occurs whether I'm using the native powershell.exe or conemu. Strangely, I am able to execute any other aliases I've tried, and it doesn't add to the $Error variable, so I have no idea where to start troubleshooting (I've tried -ErrorAction Stop and $ErrorActionPreference = 'Stop' ). As a

Unable to copy a binary to a remote Azure VM

不想你离开。 提交于 2021-01-29 07:52:06
问题 I have a Shavlink agent binary from on-prem(VMWare) that has to be copied across to a Azure VM(s). I used the public VM of the target Azure VM to perform the copy: Copy-Item –Path "C:\ProgramData\LANDESK\Shavlik Protect\Console\DataFiles\STPlatformUpdater.exe" –Destination "D:\Shavlik-Agent\" –ToSession (New-PSSession –ComputerName a.b.c.d) Unfortunately, it gives error as below: New-PSSession : [a.b.c.d] Connecting to remote server a.b.c.d. failed with the following error message : The WinRM

How do I force a function to return a single element array instead of the contained object?

左心房为你撑大大i 提交于 2021-01-28 07:52:54
问题 I have a function (actually several instances of this), but there are times that it may return a list of several elements, and there are times that it may return a single element. I want the function to return an array ( [System.Object[]] ) every time so that (on the receiving end), I can always anticipate it being an array and index into it, even if I am just pulling the 0th element. I've tried casting the return type multiple ways (see code below) ... including (for example) return @("asdf"

Import-Module works only when piped from Get-Module

前提是你 提交于 2021-01-28 02:35:48
问题 I wrote a simple PowerShell module. I need to keep more versions of the module. All paths to versions are added to $env:PSModulePath . I'm facing strange problem when importing the module to my session. This fails: Import-Module Contoso.PowerShell -RequiredVersion "0.0.2" Import-Module : The specified module 'Contoso.PowerShell' with version '0.0.2' was not loaded because no valid module file was found in any module directory. At line:1 char:1 + Import-Module Contoso.PowerShell

How to convert PSCustomObject with additional props to a custom class

旧城冷巷雨未停 提交于 2021-01-27 20:10:12
问题 Is there a neat way to convert a PSCustomObject to a custom class as a function parameter in PowerShell 5.1? The custom object contains additional properties. I'd like to be able to do something like this: class MyClass { [ValidateNotNullOrEmpty()][string]$PropA } $input = [pscustomobject]@{ PropA = 'propA'; AdditionalProp = 'additionalProp'; } function DuckTypingFtw { [CmdletBinding()] param( [Parameter(Mandatory = $True, Position = 0, ValueFromPipeline)] [MyClass] $myObj ) 'Success!' }

Data Rows to String to Array issue

本小妞迷上赌 提交于 2021-01-01 08:04:11
问题 I have a very weird problem happening. I have an object populated with a bunch of rows. I can access them all well, but I need to append a "." (dot) to every value inside it, so I end up converting each record to a string using a for each loop and adding a "." after trimming the values. The issue now however, is that I would like to assign each of these rows (And the rows have only one column/Item) to another array/object, so I can access them later. The issue is that even when I declare an

How to add same keys with different values to a hashtable in powershell?

淺唱寂寞╮ 提交于 2020-12-14 23:51:58
问题 Here is the code where i used array of hashtables $podnumbers = @(1,3,1) $podInfo = $null $buffer = 0 $podarray = foreach ($pd in $podnumbers) { $podinfo = @() for($i=0;$i -lt $pd;$i = $i+1) { $pod = Read-Host -Prompt "Assign the pod numbers for",$esxarray[$buffer] Write-Output `n } @{$pd = $pod} $buffer = $buffer + 1 } Inputs I gave for $pod is 1 = 1 ; 3 = 2,4,6 ; 1 = 3 I want my arrays of hashtable to be like below, Key : 1 Value : 1 Name : 1 Key : 3 Value : 2,4,6 Name : 3 Key : 1 Value : 3

How to add same keys with different values to a hashtable in powershell?

别来无恙 提交于 2020-12-14 23:45:28
问题 Here is the code where i used array of hashtables $podnumbers = @(1,3,1) $podInfo = $null $buffer = 0 $podarray = foreach ($pd in $podnumbers) { $podinfo = @() for($i=0;$i -lt $pd;$i = $i+1) { $pod = Read-Host -Prompt "Assign the pod numbers for",$esxarray[$buffer] Write-Output `n } @{$pd = $pod} $buffer = $buffer + 1 } Inputs I gave for $pod is 1 = 1 ; 3 = 2,4,6 ; 1 = 3 I want my arrays of hashtable to be like below, Key : 1 Value : 1 Name : 1 Key : 3 Value : 2,4,6 Name : 3 Key : 1 Value : 3

How to add same keys with different values to a hashtable in powershell?

白昼怎懂夜的黑 提交于 2020-12-14 23:43:34
问题 Here is the code where i used array of hashtables $podnumbers = @(1,3,1) $podInfo = $null $buffer = 0 $podarray = foreach ($pd in $podnumbers) { $podinfo = @() for($i=0;$i -lt $pd;$i = $i+1) { $pod = Read-Host -Prompt "Assign the pod numbers for",$esxarray[$buffer] Write-Output `n } @{$pd = $pod} $buffer = $buffer + 1 } Inputs I gave for $pod is 1 = 1 ; 3 = 2,4,6 ; 1 = 3 I want my arrays of hashtable to be like below, Key : 1 Value : 1 Name : 1 Key : 3 Value : 2,4,6 Name : 3 Key : 1 Value : 3