Questions tagged [powershell-5.1]

280 questions
3
votes
2 answers

How to extend and override Add in a collection class

Background I have a data object in PowerShell with 4 properties, 3 of which are strings and the 4th a hashtable. I would like to arrange for a new type that is defined as a collection of this data object. In this collection class, I wish to enforce…
Blaisem
  • 557
  • 8
  • 17
3
votes
3 answers

Making at least one of many parameters required in PowerShell

In PowerShell, I want to write a function, that accepts different options as parameters. It is OK, if it receives more than one parameter, but it has to receive at least one parameter. I want to enforce it through the parameter definition and not…
stackprotector
  • 10,498
  • 4
  • 35
  • 64
3
votes
1 answer

Why is Powershell output different between 5.1 and Core 7.1.4

I have a block of PowerShell code that runs a command and then massages it and writes it to a text file. $commandOutput = &"C:\Program Files (x86)\Dell EMC\Unity\Unisphere CLI\uemcli" -d $frame -noHeader /stor/config/pool/sr show foreach ($idline in…
Andrew Madsen
  • 155
  • 1
  • 12
3
votes
1 answer

PowerShell: why am I able to load multiple versions of the same .NET assembly in one session and also "bypass Dependency hell"?

I'm working in Windows 10 x64, PowerShell version 5.1. I've got multiple versions of a .NET Framework 4.0 assembly (.dll) written in C# (by myself). Assemblies are not signed. Their versions are set in AssemblyInfo.cs via [assembly:…
3
votes
1 answer

Listing multiple folders in seperate columns using PSCustomObject then selecting some?

Good morning, I have 3 folders on my desktop that contain a random amount of folders on each one. Folder 1 Sub-Folders: "here too", "more stuff", "Ranom stuff", "Something Here" Folder 2 Sub-Folders: "and here", "bored", "Here stuff", "here…
Abraham Zinala
  • 4,267
  • 3
  • 9
  • 24
3
votes
0 answers

How to get current runspace of RunspacePool

I have multiple commands run in parallel in separate runspaces, managed by a RunspacePool. How can I determine the runspace each command is running in? param ( $MaxRunspaces = 4, $JobCount = 20 ) try { $pool =…
marsze
  • 15,079
  • 5
  • 45
  • 61
3
votes
0 answers

Why does my elseif block run when specifying -WhatIf

I am having a bit of trouble understanding the documentation for SupportsShouldProcess, and was looking to see if someone can break it down a little more for me to understand. Links used MS-SupportsShouldProccess Everything you wanted to know about…
Abraham Zinala
  • 4,267
  • 3
  • 9
  • 24
3
votes
1 answer

Does PSCustomObject have an order in which its displayed to the console?

Good morning peeps, Im a big fan of making a selection from values that are returned from listed items. So, I was expirementing with making a selection out of the values returned from C:\Users, which is input into a [PSCustomObject] type, but…
Abraham Zinala
  • 4,267
  • 3
  • 9
  • 24
3
votes
1 answer

provide name to a powershell process

I have created a long running process from powershell which runs a command for quite some time as follows: Start-process "powershell" "long running command" I want to give this process a custom name or some kind of tag of type string to refer the…
Vishwanath
  • 149
  • 2
  • 14
2
votes
3 answers

Can you use Get-ChildItem -Filter to filter by filename length?

Is something like the below example code possible? Get-ChildItem $copyFilePath -Filter $_.Basename.Length -ne 22 | forEach-Object{ Copy-Item -path "$($copyFilePath)\$($_.Fullname)" } I am trying to find a way to remove…
2
votes
1 answer

Powershell Parsing of System Path Statement

Good afternoon all; I am attempting to remove multiple entries from the system path for a number of computers. Specifically, c:\program files\pythonx; c:\program files\pythonx\scripts for multiple versions of python. What I am unable to do is…
RJC
  • 21
  • 1
2
votes
1 answer

PowerShell [uri] Types Accelerator produces different AbsoluteUri

I have a local file ($URLsFile), which contains a list of URLs: http://WIND451325/Dev/Application.aspx__%__dev.com http://WIND451326/Dev/Application.aspx__%__dev.com When using the [uri] Types Accelerator with the Get-Content…
edwio
  • 198
  • 3
  • 20
2
votes
2 answers

Escaping single quote in string within Powershell before passing value to SQL

I have a script that retrieves information relating to the files within a given folder path, and then passes those values via the SQLPS module and the SQL INSERT INTO command to populate my database table. That works fine except for a few occasions…
Keith Langmead
  • 785
  • 1
  • 5
  • 16
2
votes
1 answer

How can I pipe to a PowerShell script residing in a path with spaces?

I wrote a PowerShell script that's accepting input from the pipeline plus some parameters. Now, when I want to call the script from another directory, the following doesn't work: Get-ChildItem | 'D:\My Documents\PowerShell\My-Script.ps1' -MyParam 1…
AxD
  • 2,714
  • 3
  • 31
  • 53
2
votes
1 answer

How does error handling work when you use Invoke-Command over several computers?

How does error handling work when I use Invoke-Command over many computers? For example, what if a computer name is misspelled or the user doesn't exist on a specific computer? Invoke-Command -ComputerName Computer1,Computer2,Computer3 …
Rod
  • 14,529
  • 31
  • 118
  • 230
1
2
3
18 19