• Paolo Frigo liked comment of Paul Schnackenburg on Exchange Server 2019: new features. (So far, Paul Schnackenburg has 1 likes for this comment.) 1 year, 5 months ago

    0
  • @Luc, I still prefer the for loop, but what about this solution?

    $Array = [System.Collections.ArrayList]@(
        1
        2
        3
    )
        
    foreach ($Item in $Array.clone()) {
        If ($Item -eq 2) {
            $Array.Remove($Item)
        }
    }
        
    $Array

    Do you like this one?

    0
  • @Luc Fullenwarth,

    It's getting the error, but the "2"  it''s gone from the Arraylist, you can suppress that error if you want to go down that path.

     

    Ok, an alternative to foreach will be simple for loop.

    $Array = [System.Collections.ArrayList]@(
        1
        2
        3
    )
    for ($i=0;$i -lt $Array.Count; $i++) {    
        If ($Array[$i] -eq 2) {       
            $Array.RemoveAt($i)
        }    
    }
    
    $Array

    In conclusion.

    In this case a for loop, it's for me better suited for what you want to achieve.

    It will work with no errors, it will be more obvious without hacks, it will make your code simpler to read, which I think should always be the end goal.

     

     

    0
  • Hi all,

    I think I can help you. That should be one possible answer to solve your problem.

    $Array = [System.Collections.ArrayList]@(
        1
        2
        3
    )
    
    $count = 0
    foreach ($Item in $Array) {    
        If ($Item -eq 2) {        
            $Array.RemoveAt($count)    }
        $count += 1 
    }
        
    $Array

    And the object type it's not changed either...

    PS > $Array.GetType()
    
    IsPublic IsSerial Name BaseType
    -------- -------- ---- --------
    True True ArrayList System.Object

    It took me less than one minute to solve it, because I looked it more as a developer than a sysadmin script challange.

    You're pointing to the .NET class and the answer it's very frequently in the doc: https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=netframework-4.7.2#methods

     

    0
  • Hi John,
    My guess is that you are using a variable to check in a if loop statement if the value is Key-Value is true or not. In short maybe is better to outline the difference of assigning by  value or by reference. Let me explain with a easier example with an interactive powershell session:

    PS:>$date = Get-Date
    If you print it $date now you'll have the exact time right? Sort of...

    PS:>$date
    Wednesday, 12 September 2018 5:13:00 PM

    If you print it after 10 minutes? 1 h? 1 year? Same result
    PS:>$date
    Wednesday, 12 September 2018 5:13:00 PM

    This $date is assigned once and never refreshed. So in your case it looks like you're not refreshing the variable that you're checking. An examples of it is that if I run these sequence I get the expected result all the time.

    1. Get-ItemProperty -Path "HKCU:Control PanelDesktop" -Name MenuShowDelay
    2. Set-ItemProperty -Path 'HKCU:Control PanelDesktop' -Name MenuShowDelay -Value 50
    3. Get-ItemProperty -Path "HKCU:Control PanelDesktop" -Name MenuShowDelay

    Have the expected result.
    Instead if on step 1 you store the result on a Variable and on step 3 you wan to print the value the result will not have the value updated. Does this make sense? Is it your case?

    I hope it helps.

    1+
  • Paolo Frigo's profile was updated 1 year, 11 months ago

    1+
  • 1+
  • Paolo Frigo liked Create PowerShell scheduled jobs. (So far, This post has 5 likes) 2 years ago

    1+
  • Paolo Frigo changed their profile picture 2 years, 1 month ago

    1+
  • I agree with you in managing servers with SCCM, that leverages WSUS and I also follow the common sense of applying changes on a test ring and after a positive result move to the next one. Keep in mind that as admins we also apply the same common practice to group policies and registry changes.

    If this issue creates an outage it means that the some of the servers weren't patched and the request or incident needs to be managed according to the service.
    Regarding the production environment, it depends by the kind of access and accountability that you have and most importantly which process to follow to apply any change, if updates are scheduled for patching Tuesday or 1 month behind and so on.

    But in this case really mitigation strategy almost takes longer in total more to test, deploy than fix it once. In my case for workarounds I suggested to rdp to an un-patched client that was offline and use it as a jumpbox to rdp to the un-patched hosts, lucky that in my case the hosts to patch were really infinitely small percentage.

    1+
  • Good Article Mohamed! I will strongly suggest to read the article and in detail CVE-2018-0886. When I found that issue few weeks ago after the CVE article I've decided to patch immediately few servers, the main reason is that "Any change to Encryption Oracle Remediation requires a reboot." so I preferred to apply the hotfix instead of applying a regkey or create a group policy that should apply the change and after patching revert the change.
    Using Invoke-Command and Get-HotFix is possible to check/scan quickly if servers/hosts are already patched or with get-winevent (System, EventID 6041) on some clients to collect text message of the connection failed without even trying to RDP on each computer on different network or environment.

    1+
  • Load More