Paolo Frigo liked Install Subsystem for Linux in Windows 10 LTSC and Server 2019. (So far, This post has 3 likes) 3 years, 2 months ago
Paolo Frigo liked The new Azure PowerShell Az module. (So far, This post has 4 likes) 3 years, 2 months ago
Paolo Frigo liked Installing OpenSSH on Windows 10 (1803 and higher) and Server 2019. (So far, This post has 3 likes) 3 years, 2 months ago
Paolo Frigo liked Exchange Server 2019: new features. (So far, This post has 4 likes) 3 years, 3 months ago
Paolo Frigo liked comment of Paul Schnackenburg on Exchange Server 2019: new features. (So far, Paul Schnackenburg has 1 likes for this comment.) 3 years, 3 months ago
Paolo Frigo replied to the topic The foreach/remove object challenge in
PowerShell Forum 3 years, 3 months ago
@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?
Paolo Frigo replied to the topic The foreach/remove object challenge in
PowerShell Forum 3 years, 3 months ago
@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.
Paolo Frigo and
Luc Fullenwarth are now friends 3 years, 3 months ago
Paolo Frigo replied to the topic The foreach/remove object challenge in
PowerShell Forum 3 years, 3 months ago
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
Nice article Tim!
@Calli, if you want to sign your powershell script I suggest you to read this about_signing doc.I’ve published an article on my blog as well if you have some basic examples of code signing with a self-signed certificate.
Anatoliy and
Paolo Frigo are now friends 3 years, 4 months ago
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 PMIf you print it after 10 minutes? 1 h? 1 year? Same result
PS:>$date
Wednesday, 12 September 2018 5:13:00 PMThis $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.
- Get-ItemProperty -Path “HKCU:Control PanelDesktop” -Name MenuShowDelay
- Set-ItemProperty -Path ‘HKCU:Control PanelDesktop’ -Name MenuShowDelay -Value 50
- 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.
Paolo Frigo's profile was updated 3 years, 9 months ago
Paolo Frigo liked Managing disks with PowerShell. (So far, This post has 1 likes) 3 years, 9 months ago
Paolo Frigo liked Create PowerShell scheduled jobs. (So far, This post has 5 likes) 3 years, 9 months ago
Paolo Frigo changed their profile picture 3 years, 11 months ago
Paolo Frigo commented on
Install Windows updates remotely with the PowerShell 3 years, 11 months ago
Maybe I’m wrong but I think the cmd-let is included on Michael Gajda’s
Windows Update PowerShell Module- https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc
- https://www.powershellgallery.com/packages/PSWindowsUpdate/2.0.0.4
Paolo Frigo commented on RDP authentication error due to the CredSSP encryption oracle remediation error 3 years, 12 months ago
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.
Paolo Frigo commented on RDP authentication error due to the CredSSP encryption oracle remediation error 3 years, 12 months ago
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.Paolo Frigo and
Paolo Maffezzoli are now friends 3 years, 12 months ago
- Load More