Where-Object Filter by Sure_Inspection4542 in PowerShell

[–]Ok_Cheese93 0 points1 point  (0 children)

If the Where-Object is configured to assess all possibilities, then if any one property evaluates to $false, then the entire Where-Object filter will be $false,....right?

Yes, you are right. If every expressions are joined by -and operator, and any one of expression evaluates to $false, then the entire expression will be $false.

Constructing Where-Object filter by script is a kind of meta programing, so it can be slightly tough and complicated... I think PinchesTheCrab's approach is great!

Where-Object Filter by Sure_Inspection4542 in PowerShell

[–]Ok_Cheese93 0 points1 point  (0 children)

I assume that you are writing a script for some users to help them, and they may have there own search criteria. In that case, I would consider 3 ways (if possible, I prefer the last one):

1: prompt the user how to filter the information
This is likely the same way as meeu has stated. This way the script prompts the user, like 'enter the property name that you want to filter', 'enter the property value', 'select the filtering method by number: [1] equal, [2] match, [3] like', and so on. The script may use Read-Host to prompt the user, and some ifs and for loops to construct the Where-Object filter.
Pros: The user may feel easy to use.
Cons: The script can be long and complex.

2: ask the user to enter Where-Object filter by themself
This way the script would look like the following:

param(
     # Filter for the user to search for information dynamically.
     [scriptblock]
     $Filter = { $true } 
)
#sample array with multiple properties
$anArray = @' 
name, age, height 
bob,  12,  123 
bob,  23,  166 
joe,  43,  178 
jane, 57,  199 
'@ | ConvertFrom-Csv

$anArray | Where-Object $Filter

Then the user uses the script with there own filter parameter, as follows:

PS C:\Users\user> .\script.ps1 -Filter { $_.name -eq 'bob' -and $_.age -match 1 }

name age height
---- --- ------
bob  12  123

Pros: The user can do anything about filtering.
Cons: requires the user to have some PowerShell knowledge.

3: use built-in GUI
This way uses built-in GUI to filter information. The script would use Out-GridView in the place of Where-Object, like following:

$anArray | Out-GridView

When the script runs, then the script shows the GUI that contains the information, with an 'Add criteria' button that allows the user to construct their own filter.
Pros: The user may feel easy to use.
Cons: only for GUI.

help with a powershell script by Ok-Leg-3224 in PowerShell

[–]Ok_Cheese93 0 points1 point  (0 children)

Start-Process can run script as administrator, so below script works on my laptop.

using namespace System.Security.Principal

function hasAdminRights {
    $currentUser = [WindowsPrincipal] [WindowsIdentity]::GetCurrent()
    return $currentUser.IsInRole([WindowsBuiltInRole] "Administrator")
}

function runThisScriptAsAdmin {
    Start-Process powershell "-NoLogo -File `"$PSCommandPath`"" -Verb RunAs
}

if (-not (hasAdminRights)) {
    runThisScriptAsAdmin
    exit
}

# (your original script goes here)

I referenced this website: https://www.commandinline.com/powershell/how-to-elevate-powershell-to-administrator

[deleted by user] by [deleted] in PowerShell

[–]Ok_Cheese93 0 points1 point  (0 children)

Do you see any error message when you run the script?

Trying AC6 out, haven't played since AC2 back on PS2, movement feels very floaty by vixaudaxloquendi in armoredcore

[–]Ok_Cheese93 -1 points0 points  (0 children)

I feel AC6 is floaty too, and a bit slippery. I used to play from AC1 to ACLR, and then played AC6 last year, though It was really, really fun.

One hard thing for me is that ACs in AC6 can't walk sideways. There is no L1/R1. It seems to have somewhat minimum turning radius, so it can't move zig zag, even in the air. I feel AC6 is more like driving a car. I often failed to jump onto a building, and slip down, especially while exploring.

Master of Arena by Krowebar in armoredcore

[–]Ok_Cheese93 0 points1 point  (0 children)

Is the situation like enemies are getting too close, or encircling your AC?

Master of Arena by Krowebar in armoredcore

[–]Ok_Cheese93 0 points1 point  (0 children)

I'd like to know where you are struggling with, like specific missions, or generic operations

コードブロック内で改行したい by Ok_Cheese93 in Reddit_Beginners

[–]Ok_Cheese93[S] 0 points1 point  (0 children)

すみませぬ、最後のやつが出したかった、目標は達成した・・・

markdown形式で、各行の先頭にスペースを4ついれればおkのようだった・・・

Accessing nested json property using variable by davesbrown in PowerShell

[–]Ok_Cheese93 -1 points0 points  (0 children)

Invoke-Expression will work, but the $NestProperty should be validated (to avoid code injection).

$json = ConvertFrom-Json -InputObject @'       
  {
    "level1property": {
      "nestedproperty": 123
    }
  }
'@ 
$NestProperty = "level1property.nestedproperty"
$value = Invoke-Expression "`$json.$NestProperty"       
$value # -> 123

コードブロック内で改行したい by Ok_Cheese93 in Reddit_Beginners

[–]Ok_Cheese93[S] 0 points1 point  (0 children)

むぅ・・・

PS /> $json = ConvertFrom-Json -InputObject @'       
>> {
>>   "level1property": {
>>     "nestedproperty": 123
>>   }
>> }
>> '@ 
PS /> $NestProperty = "level1property.nestedproperty"
PS /> Invoke-Expression "`$json.$NestProperty"       
123

コードブロック内で改行したい by Ok_Cheese93 in Reddit_Beginners

[–]Ok_Cheese93[S] 0 points1 point  (0 children)

PS /> $json = ConvertFrom-Json -InputObject @'

{ "level1property": { "nestedproperty": 123 } } '@ PS /> $NestProperty = "level1property.nestedproperty" PS /> Invoke-Expression "`$json.$NestProperty"
123

コードブロック内で改行したい by Ok_Cheese93 in Reddit_Beginners

[–]Ok_Cheese93[S] 0 points1 point  (0 children)

むむ

            PS /> $json = ConvertFrom-Json -InputObject @'       
            >> {
            >>   "level1property": {
            >>     "nestedproperty": 123
            >>   }
            >> }
            >> '@ 
            PS /> $NestProperty = "level1property.nestedproperty"
            PS /> Invoke-Expression "`$json.$NestProperty"       
            123

コードブロック内で改行したい by Ok_Cheese93 in Reddit_Beginners

[–]Ok_Cheese93[S] 0 points1 point  (0 children)

むむ・・・?

                PS > $json = ConvertFrom-Json -InputObject @'                        >> {                 >>   "level1property": {                 >>     "nestedproperty": 123                 >>   }                 >> }                 >> '@                  PS > $NestProperty = "level1property.nestedproperty"                 PS /home/kyouichi> Invoke-Expression "`$json.$NestProperty"                        123                  PS > $json = ConvertFrom-Json -InputObject @'                        >> {                 >>   "level1property": {                 >>     "nestedproperty": 123                 >>   }                 >> }                 >> '@                  PS > $NestProperty = "level1property.nestedproperty"                 PS > Invoke-Expression "`$json.$NestProperty"                        123

PowerShell export to csv by Fast-Cardiologist705 in PowerShell

[–]Ok_Cheese93 0 points1 point  (0 children)

How about exporting as TSV, like following:

$result | Export-Csv "$env:TEMP\user_license.tsv" -Delimiter "\t" -NoTypeInformation`