Questions tagged [powershell-5.1]
280 questions
                    
                    6
                    
            votes
                
                8 answers
            
        Powershell sort IP Addresses in txt file
I have a plain text file containing some IPs like this:
194.225.0.0 - 194.225.15.255
194.225.24.0 - 194.225.31.255
62.193.0.0 - 62.193.31.255
195.146.53.128 - 195.146.53.225
217.218.0.0 - 217.219.255.255
195.146.40.0 - 195.146.40.255
85.185.240.128…
         
    
    
        Saeed
        
- 3,255
- 4
- 17
- 36
                    5
                    
            votes
                
                2 answers
            
        What is the simplest form of Dynamic Parameters?
Trying to get a better understanding of Dynamic Parameters, but something keeps bothering me. All examples I've found across the outer-webs (internet), the parameter attributes are always defined/included.
Here's what I'm working with:
Function…
         
    
    
        Abraham Zinala
        
- 4,267
- 3
- 9
- 24
                    5
                    
            votes
                
                2 answers
            
        Get all AD computers created after a certain date
I created the script below to find all Unix computers created since a specific date. It doesn't return an error, but it doesn't work either. There is only one date used in the script but both formats have same outcome.
Neither date format fails, but…
         
    
    
        Leo Torres
        
- 673
- 1
- 6
- 18
                    5
                    
            votes
                
                1 answer
            
        Converting to and from Base64 in Powershell 5.1
I've found a couple of resources (including Convert base64 string to file, which is practically a duplicate here since it's one of the resources I used to build this) but I can't seem to get it working.
I've got the following code (roughly -…
         
    
    
        Epsilon
        
- 73
- 2
- 5
                    4
                    
            votes
                
                1 answer
            
        PrintOut Code Works On PowerShell v 5.1, But Not On 7.3
I am trying to print parts of several docx files. The code below works in Windows PowerShell 5.1, but not in PowerShell 7.3. I would like to understand why and help updating the code so it works in PowerShell 7.3.
$path =…
         
    
    
        mwb9aa
        
- 41
- 2
                    4
                    
            votes
                
                1 answer
            
        Can't find System.Net.Http.HttpClient class
I am trying to create HTTP client with PowerShell.
In some places like this and this, it shows that I need to create an object like that:
$client = [System.Net.Http.HttpClient]::new()
But PowerShell doesn't find any class after System.net.Http..
In…
         
    
    
        E235
        
- 11,560
- 24
- 91
- 141
                    4
                    
            votes
                
                1 answer
            
        How can I use tar and tee in PowerShell to do a read once, write many, raw file copy
I'm using a small laptop to copy video files on location to multiple memory sticks (~8GB).
The copy has to be done without supervision once it's started and has to be fast.
I've identified a serious boundary to the speed, that when making several…
         
    
    
        mist42nz
        
- 97
- 1
- 8
                    4
                    
            votes
                
                0 answers
            
        Get NTFS Effective Permission on Folder
I am looking into recreating the same results as the the Get-NTFSEffectiveAccess cmdlet provided in the NTFSSecurity module. Unfortunately, I need to re-invent the wheel using just PowerShell (as it's the only thing I know).
For the most part, I…
         
    
    
        Abraham Zinala
        
- 4,267
- 3
- 9
- 24
                    4
                    
            votes
                
                1 answer
            
        cmd.exe --> powershell.exe "-File" and "-Command" in the same line
test.ps1 contains:
echo ok
I have a line in the command prompt (cmd.exe) that needs to call powershell.exe passing both the "-File" option and the "-Command" option.
With this wrong syntax:
powershell.exe -File "test.ps1" -Command "echo…
         
    
    
        Mario Palumbo
        
- 693
- 8
- 32
                    4
                    
            votes
                
                1 answer
            
        Why does the pipeline not work on converted json objects?
Consider the following code:
$data = '[
    {
        "Name":  "banana",
        "Color":  "yellow"
    },
    {
        "Name":  "kiwi",
        "Color":  "green"
    },
    {
        "Name":  "apple",
        "Color":  "red"
    }
]'
# Returns 3…
         
    
    
        DarkLite1
        
- 13,637
- 40
- 117
- 214
                    4
                    
            votes
                
                1 answer
            
        PowerShell: Import-Module or Add-Type for .NET assemblies?
I'm using PowerShell 5.1, Windows 10 x64.
Which of these 2 cmdlets should I use to load .NET assemblies (in particular .NET Framework 4+ assemblies) into PowerShell? What's the core difference between them? I want to load assemblies for accessing…
         
    
    
        TheNightdrivingAvenger
        
- 222
- 2
- 13
                    4
                    
            votes
                
                2 answers
            
        Using PowerShell backtick character for snippet execution doesn't work
When I run the backtick (`) command on this snippet:
Get-WmiObject win32_service | Where-Object { $_.pathname -notlike "C:\windows\*" -and $_.startmode -eq "auto" -and $_.startname -eq "localsystem"} | Select-Object displayname, `
pathname,…
         
    
    
        Birdie
        
- 47
- 6
                    4
                    
            votes
                
                1 answer
            
        ScriptProperty can't access script's cmdlets when invoked as a command
Given code such as this MRE:
function Get-One {1}
Update-TypeData -TypeName 'Demo' -MemberType 'ScriptProperty' -MemberName 'Test1' -Value {Get-Date}
Update-TypeData -TypeName 'Demo' -MemberType 'ScriptProperty' -MemberName 'Test2' -Value…
         
    
    
        JohnLBevan
        
- 22,735
- 13
- 96
- 178
                    3
                    
            votes
                
                1 answer
            
        Index out of Range exception with null returned from a static function
I get a strange exception on calling a static function that return a null object:
Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index
At H:\test\issue_nullret.ps1:12 char:5
+    …
         
    
    
        yacc
        
- 2,915
- 4
- 19
- 33
                    3
                    
            votes
                
                1 answer
            
        Can't Install `Az` module in PowerShell 7.3.x
My Windows 11 laptop has two versions of PowerShell installed:
5.1.22621.963
7.3.1 (PowerShell Core)
Following MS instructions, I want to install the Az module in PowerShell 7.3, so I use this command:
Install-Module -Name Az -Scope CurrentUser…
         
    
    
        Brent Arias
        
- 29,277
- 40
- 133
- 234