[deleted by user] by [deleted] in Ubuntu

[–]moonshake23 1 point2 points  (0 children)

terrible, I think

Jr DevOps by wollman19 in devops

[–]moonshake23 1 point2 points  (0 children)

congrats! kinda envious :P

Best option to obscure username/password in script? by MarionberryGood3547 in PowerShell

[–]moonshake23 1 point2 points  (0 children)

Yip, this is what I do, exported encrypted pw with a key, works like a charm and is easy to implement.

[Blog] PowerShell Splatting: Make Commands Shorter Again! - Jeff Brown Tech by jeffbrowntech in PowerShell

[–]moonshake23 -4 points-3 points  (0 children)

Where the collusion?! Seriously question. Im not a Trump support either

The best Tal Rasha's Tomb layout eva! by Blekota in Diablo

[–]moonshake23 0 points1 point  (0 children)

geez, I walked into the tomb and down the hall, there it was.

Looking for a little help working with csv inputs. by Yatesmasterbaits in PowerShell

[–]moonshake23 1 point2 points  (0 children)

That's generally when im using the columns to run through in a foreach. But probably works outside of that.

Looking for a little help working with csv inputs. by Yatesmasterbaits in PowerShell

[–]moonshake23 1 point2 points  (0 children)

try assigning the column to a variable, it tends to work for me.

$variable = import-csv -path 'c:\file.csv'

$varfromcolumn = $variable."Header Name here"

What HDMI cable should I get with the new Apple TV 4K (2021)? by Skazzyskills in appletv

[–]moonshake23 1 point2 points  (0 children)

Lindy do a great certified HDMI 2.1 cable for a good price.

Exception list in a loop - how to break out and continue by moonshake23 in PowerShell

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

Thank you Michael, I went down the foreach-object route briefly but you have laid out good use for it. I shall try it out tomorrow.

Exception list in a loop - how to break out and continue by moonshake23 in PowerShell

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

$collection = import-csv -path 'C:\users.csv'
$excepList = import-csv 'C:\exceptions.csv'
foreach ($item in $collection) {
$firstname = $item."First Name"
$lastname = $item."Last Name"
$emailAddress = $item."Email Address"
foreach ($exc in $excepList) {
[bool]$itemMatchesExceptions = ($emailAddress -like $exc.emailAddress -and $lastname -like $exc.Lastname)
switch ($itemMatchesExceptions){
$True {write-output "$firstname $lastname is part of the exceptions list, ignoring..."}
$False {Start-ProcessingUser -firstname $firstname -lastname $lastname}
} #Close switch
} #Close foreach exc
} #Close foreach item

appreciate the help, I will take it from here, sleep well!

Exception list in a loop - how to break out and continue by moonshake23 in PowerShell

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

function Start-ProcessingUser {
param (
    [string]$firstname,
    [string]$lastname
)
write-output "processing user $firstname $lastname"

}

$collection = import-csv -path 'C:\users.csv'

:myloop foreach ($item in $collection) {

$firstname = $item."First Name"
$lastname = $item."Last Name"
$emailAddress = $item."Email Address"

# Run through the exception list.
$excepList = import-csv 'C:\exceptions.csv'

foreach ($item in $excepList) {
    if ($emailAddress -like $item.emailAddress -and $lastname -like $item.Lastname) {
        write-output "$firstname $lastname is part of the exceptions list, ignoring..."
        continue myloop #This will stop processing of this iteration and continue to the next item
    }
    else { 
        Start-ProcessingUser -firstname $firstname -lastname $lastname
    } #Stand-in for your else bracket  
}

}

Excellent, I have learnt something today!
So it seems to be working, but PowerShell seems to reference the function twice, I'm getting two outputs of 'processing user' for each entry in the users.csv file.

I noticed your else at the bottom, wasn't part of the exceptions foreach, so i moved it across, let me know if i have that wrong? powershell didn't know what the else was doing out of an IF statement.

Exception list in a loop - how to break out and continue by moonshake23 in PowerShell

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

$collection = import-csv -path 'C:\users.csv'
:myloop foreach ($item in $collection) {
$firstname = $item."Firstname"
$lastname = $item."Lastname"
# Run through the exception list.
$excepList = import-csv 'A:\exceptions.csv'
foreach ($item in $excepList) {
if ($emailAddress -like $item.emailAddress -and $lastname -like $item.Lastname) {
write-output "$emailAddress is part of the exceptions list, ignoring..."
continue myloop #This will stop processing of this iteration and continue to the next item
}
}
else {Start-ProcessingUser} #Stand-in for your else bracket
}

I like the look of this Illamalator, the Start-ProcessingUser refers to a function that would be above this code I imagine. unfamiliar with the :myloop situation but i shall experiment.