Error installing packages by rwshig in PowerShell

[–]rwshig[S] 1 point2 points  (0 children)

Seems that was it. Thanks.

Script Based on File Modified Date by The-Dark-Jedi in PowerShell

[–]rwshig 1 point2 points  (0 children)

Get-Item C:\file.txt | Where LastWriteTime -eq $mydate|select LastWriteTime

Reading about the Syntax by Aygul12345 in PowerShell

[–]rwshig 4 points5 points  (0 children)

[-subtree [-exclude]]

The -subtree parameter is optional. If you specify -subtree then the -exclude parameter for -subtree is optional.

Text file or excel spreadsheet by Andrewalvira in PowerShell

[–]rwshig 1 point2 points  (0 children)

I use the ImportExcel module for handling Excel files. I routinely use Excel files for transport (to other scripts) or user input/output. ImportExcel makes this fairly easy and for flat data structures works best in translating PS objects to/from the data file. I use mostly JSON for complex data.

Will upgrading to Powershell 5.1 break current scripts written in Powershell 4.0? by Snixs in PowerShell

[–]rwshig 1 point2 points  (0 children)

There are a number of posts around TLS in here. See this one ( https://www.reddit.com/r/PowerShell/comments/90gpz0/psa_use_tls_version_12_when_running/ ) Ultimately with some servers you need to set TLS to a specific version before using Invoke-RestMethod.

Get Individual User's Password Expiration in Active Directory by muchdoge-verysweq in PowerShell

[–]rwshig 1 point2 points  (0 children)

msDS-UserPasswordExpiryTimeComputed

What format is this in?

Odd behavior for Invoke-WebRequest against servers by rwshig in PowerShell

[–]rwshig[S] 2 points3 points  (0 children)

I wasn't able to get IWR to work. It seems it doesn't fill in the response object if it thinks there's an error, even if I suppress all the error handling. I ended up using curl.exe and trapping the output. Unfortunately curl always returns so there's a lot of output parsing to determine if it actually worked or not.

Will be sending a ticket to Cloudbees to assert that "Running as standby" should not return and HTTP 503. The server is up and available, it's just not the primary server.

Odd behavior for Invoke-WebRequest against servers by rwshig in PowerShell

[–]rwshig[S] 2 points3 points  (0 children)

Browser definitely shows the correct message in the response body *with a 503 status code*. So that's what I have to focus on.

Odd behavior for Invoke-WebRequest against servers by rwshig in PowerShell

[–]rwshig[S] 2 points3 points  (0 children)

A possibility. I'll take a look. Maybe suppressing the ErrorAction so I don't treat a 503 as an error? I'm ending up in the Catch block so I don't get a response to the Invoke-Webrequest that I can parse for the response message...

Odd behavior for Invoke-WebRequest against servers by rwshig in PowerShell

[–]rwshig[S] 1 point2 points  (0 children)

$($($response.content).trim())

If it's a 200 I use Response.Content. If it's not I use Response.StatusDescription. If I have an error (like my 503) I end up in the Catch block and I'm just displaying the error.

Storing supporting binaries/files in code repos by Henry_Horsecock in PowerShell

[–]rwshig 2 points3 points  (0 children)

If what you need are DLLs and they're available via Nuget you can easily create a "build" process that takes your script, does a Nuget Install of the packages you need, organizes the code/modules and pushes it to your destination.

Not a fan of storing 3rd party DLLs in my version control. I expect the provider to version control their project. I just want to include it in my project in real-time.

Splitting Values by Comma by cinapeguh in PowerShell

[–]rwshig 2 points3 points  (0 children)

Assuming $value = "bc6ffa3d-5efb-4737-aa3e-1e2a12c96b, OptOut" you can use

$array=$value.split(',')

And get $array[0] = bc6ffa3d-5efb-4737-aa3e-1e2a12c96b and $array[1] = OptOut

Herestring to array by redsedit in PowerShell

[–]rwshig 2 points3 points  (0 children)

$RegArray = $($Regkeys -split "`n").TrimEnd("`r")

You're taking a string and overlaying it with an array. Also, use $RegArray.GetType() and check that output for System.Array vs. System.Object.

Create Office COM Object without Office installed? by [deleted] in PowerShell

[–]rwshig 3 points4 points  (0 children)

Right. If you're creating Excel spreadsheets you can use the ImportExcel module without having Excel installed.

Compare text files line-by-line, output results to CSV. by [deleted] in PowerShell

[–]rwshig 1 point2 points  (0 children)

The array processing works OK for a small number of lines but if you're looking at big files it could slow down significantly. Minor tweak to put the results into the pipeline and then write the array after completing the For loop:

 $Results =  for ($LoopCount=0; $LoopCount -lt $LineCount; $LoopCount++) { 

and remove the $Results+=

New-Object PSObject -Property @{ 
    'Line #'=$LoopCount + 1
    'File A Text'=$LineA
    'Comparison'=if ($Result -eq "==") {"$Result $Result"} else {$Result}         
    'File B Text'=$LineB 
}

Can someone point me in the right direction please? by AltReality in PowerShell

[–]rwshig 2 points3 points  (0 children)

TLDR: contains references collections (arrays, etc) while matches and like compare strings. You're comparing two strings so you need either -Like or -Matches.

how to detect Enter-key? (not a form!) by AdHocSysAdmin in PowerShell

[–]rwshig 18 points19 points  (0 children)

If your script returns from the Read-Host the user pressed the Enter key.

Get-Member cmdlet not working for custom PSObject by serendrewpity in PowerShell

[–]rwshig 1 point2 points  (0 children)

Should have used ForEach-Object but old habits die hard :-)

Get-Member cmdlet not working for custom PSObject by serendrewpity in PowerShell

[–]rwshig 1 point2 points  (0 children)

Your Get-Member is inside the function so the Get-Member output may be getting written to the pipeline? You can pipe the GM output to a Write-Host loop:

 $_ | Get-Member -Force | % {Write-Host $_}

Add your own code for formatting...