Questions tagged [powershell-5.1]

280 questions
2
votes
1 answer

Powershell removing commandlet flag altogether depending on powershell version

With Powershell 7 there have been several changes to Invoke-RestMethod. I've written some modules that are wrappers for several Invoke-RestMethod calls to simplify the interaction with our API for my colleagues. In Powershell 5.1 this code runs…
Tanaka Saito
  • 943
  • 1
  • 17
  • 40
2
votes
2 answers

Powershell ToString() behaviour - replacing 0 in a string during ForEach-Object {$_.ToString('test_0')}

I've encountered some Powershell behaviour that I didn't expect while using ForEach-Object and ToString. Digits are being replaced automatically and I can't quite graps the rule for the substitution from the output alone. Here's a small simplified…
Telefonmann
  • 315
  • 1
  • 2
  • 13
2
votes
0 answers

Invoke-WebRequest – Authentication fails (401) on Windows PowerShell but not on PowerShell 7

I'm trying to reach our Artifactory repository using the following PowerShell command: $dest = 'https://artifactory.****.de/artifactory/*********/' Invoke-WebRequest -Uri $dest -Credential (Get-Credential) While this works flawlessly in PowerShell…
AxD
  • 2,714
  • 3
  • 31
  • 53
2
votes
1 answer

How would I get all values of a Powershell Object added to a collection from a Foreach loop?

I have this function that takes the InterfaceIndex from $interfaceIPs and obtains the matching NetRoute data, and puts all of that together in a collection. Currently on the terminal I have 3 separate active IPv4 addresses, but when I print the…
Nick Keele
  • 35
  • 5
2
votes
0 answers

Is Start-Process -Passthru unable to grab the process ID?

I have a PowerShell script able to open and close .txt and .exe via a returned PID from Start-process $type -Passthru. However, if I try to do this same thing with .pngs I get this error: Start-Process : This command cannot be run completely…
2
votes
1 answer

Why is [datetime] converting this UTC time correctly and how can I replicate that with ParseExact

I feel silly that I cannot figure this one out on my own. I have dates coming from the CarbonBlack API e.g. 2022-02-15-172040 which are in UTC The [datetime] type cast works fine if I remove the seconds portion of the string PS M:\Scripts>…
Matt
  • 45,022
  • 8
  • 78
  • 119
2
votes
1 answer

How can I replace a character of a item with a specific character in powershell?

I have the an array called $Map that has 29 strings of 23 characters. With the $CharY variable I specify the index of an item and with the $CharX variable I specify which character of that item should be replaced. How do I actually replace this…
PlatoHero
  • 31
  • 5
2
votes
1 answer

invoke-WebRequest and a proxy that refuses to die in Powershell 5.1

I have a Windows Server 2019 instance that used to have a proxy server configured in its proxy setting but has since been disabled from Proxy Settings -> Proxy If I run the powershell 5.1 command: Invoke-WebRequest https:// then i'm still…
2
votes
1 answer

Comparison operator and function references

Referencing a function as the left-hand side of the -eq operator produces results that I can't explain: PS C:\> function mj { 23 } PS C:\> mj -eq 23 23 PS C:\> mj -eq 45 23 The first case almost makes it seem as though the function's return value…
Mike
  • 123
  • 1
  • 5
2
votes
2 answers

How do I reference a ListBox item

Sometimes things (PowerShell?) gets too smart on me... In this case, I would like change the Text property of a WinForms ListBox item selected by its index (not the SelectedItems). The point here is that $ListBox.Items[$CurrentIndex] appears to be a…
iRon
  • 20,463
  • 10
  • 53
  • 79
2
votes
1 answer

Get-Job Format-Table with Runtimes of Jobs

I am trying to write a PowerShell 5.1 script for monitoring jobs. I am having a problem writing a proper Get-Job table, the following is what I have. Get-Job | Format-Table -AutoSize -Property name, state, @{name = 'Runtime'; Expression =…
RubrFox
  • 23
  • 2
2
votes
1 answer

What does the `-Sanitize` switch of the `Clear-Disk` cmdlet do in PowerShell?

The Clear-Disk cmdlet seems to have a currently undocumented -Sanitize switch: PS> Get-Command Clear-Disk | Select-Object -ExpandProperty ParameterSets | ? {$_.Name -like 'ByName'} | Select-Object -ExpandProperty Parameters | ? {$_.Name -like…
stackprotector
  • 10,498
  • 4
  • 35
  • 64
2
votes
0 answers

Do the newer CIM cmdlets follow a different protocol for remote systems?

I've been trying to install some remote updates that are in error state (well any updates in general), but continue to get and error of: No instance found with given property values. . . that's it. That's the only error that is displayed with no…
Abraham Zinala
  • 4,267
  • 3
  • 9
  • 24
2
votes
1 answer

Function only diplays properties once

I have a function that for some reason, just seems to only display $Properties once, no matter how many users are passed to the script. Tried to throw in just the $user passed into the script to display but, that too only displays once. Not too sure…
Abraham Zinala
  • 4,267
  • 3
  • 9
  • 24
2
votes
1 answer

How to confirm system initialization is complete using using PowerShell?

I have a working PS script that gets the boot time of remote servers #$ServerArray is the list of servers $cso = New-CimSessionOption -Protocol Dcom $cs = New-CimSession -ComputerName $ServerArray -SessionOption $cso Get-CimInstance -CimSession $cs…
Ruben_PH
  • 1,692
  • 7
  • 25
  • 42
1 2
3
18 19