środa, 24 kwietnia 2019

An error occurred while enumerating through a collection: Collection was modified; enumeration operation may not execute...

Below code will generate above error:
$someHashTable = @{}
$someHashTable.Add("key1", "value1")
$someHashTable.Add("key2", "value2")
$someHashTable.Keys | %{ $someHashTable[$_] = "newValue" }

It should looks like below code - collection of keys must be copied to fresh new collection.
$someHashTable = @{}
$someHashTable.Add("key1", "value1")
$someHashTable.Add("key2", "value2")
$keys = @(); $someHashTable.Keys | %{ $keys += $_ }
$keys | %{ $someHashTable[$_] = "newValue" }

poniedziałek, 22 kwietnia 2019

dynamic arrays in poweshell

By default arrays in Powershell are not dynamic, so the only way to deal with it is to use:
 
c:\>[System.Collections.ArrayList]$DynamicArray = @()
c:\>$DynamicArray.IsFixedSize 
False
c:\>$DynamicArray.Add("june")
c:\>$DynamicArray.Add("june")
c:\>$DynamicArray
june
june
c:\>$DynamicArray.Remove("june")
c:\>$DynamicArray
june
c:\>
We can pass this list to update membership in a group in Active Directory.
c:\>$DynamicArray = "january", "february", "march"
c:\>$DynamicArray += "april"
c:\>$DynamicArray += "april"
c:\>$DynamicArray
january
february
march
april
april
c:\>
So we can do it this way also.

czwartek, 11 kwietnia 2019

operatingSystem and operatingSystemVersion in my environment

Tidying time - what I've got in my current environment?
10.0 (14393) Windows Server 2016 Standard
6.3 (9600) Windows Server 2012 R2 Datacenter
6.3 (9600) Windows Server 2012 R2 Standard
6.2 (9200) Windows Server 2012 Datacenter
6.2 (9200) Windows Server 2012 Enterprise
6.2 (9200) Windows Server 2012 Standard
6.1 (7601) Windows Server 2008 R2 Enterprise Service Pack 1
6.1 (7600) Windows Server 2008 R2 Datacenter
6.1 (7600) Windows Server 2008 R2 Enterprise
6.1 (7600) Windows Server 2008 R2 Standard
6.0 (6003) Windows Server® 2008 Standard Service Pack 2
6.0 (6002) Windows Server 2008 Enterprise Service Pack 2
6.0 (6002) Windows Server 2008 Standard Service Pack 2
6.0 (6002) Windows Server® 2008 Standard Service Pack 2
6.0 (6002) Windows Server® 2008 Standard without Hyper-V Service Pack 2
6.0 (6001) Windows Server® 2008 Enterprise Service Pack 1
6.0 (6001) Windows Server® 2008 Standard Serivce Pack 1
5.2 (3790) Windows Server 2003 Service Pack 2
5.2 (3790) Windows Server 2003 Service Pack 1
5.2 (3790) Windows Server 2003
5.0 (2195) Windows 2000 Server Service Pack 4
5.0 (2195) Windows 2000 Server Service Pack 2
5.0 (2195) Windows 2000 Server Service Pack 1

10.0 (17763) Windows 10 Enterprise LTSC
10.0 (17763) Windows 10 Enterprise
10.0 (17763) Windows 10 Pro
10.0 (17134) Windows 10 Enterprise
10.0 (16299) Windows 10 Enterprise
10.0 (16299) Windows 10 Pro
10.0 (15063) Windows 10 Enterprise
10.0 (14393) Windows 10 Enterprise 2016 LTSB
10.0 (14393) Windows 10 Enterprise
10.0 (10586) Windows 10 Enterprise
10.0 (10240) Windows 10 Enterprise
10.0 (9926) Windows 10 Enterprise Technical Preview
6.3 (9600) Windows 8.1 Enterprise
6.3 (9600) Windows 8.1 Pro
6.2 (9200) Windows 8 Enterprise
6.2 (9200) Windows 8 Pro
6.2 (8400) windows 8 Release Preview
6.2 (8250) Windows 8 Consumer Preview
6.2 (8102) Windows Developer Preview
6.2 (6001) Windows Vista™ Ultimate Service Pack 1
6.1 (7601) Windows Embedded Standard Service Pack 1
6.1 (7601) Windows 7 Ultimate Service Pack 1
6.1 (7601) Windows 7 Enterprise Service Pack 1
6.1 (7601) Windows 7 Professional N Service Pack 1
6.1 (7601) Windows Workstation Service Pack 1
6.1 (7600) Windows 7 Ultimate Evaluation
6.1 (7600) Windows 7 Ultimate
6.1 (7600) Windows 7 Enterprise
6.1 (7201) Windows 7 Ultimate
6.1 (7100) Windows 7 Ultimate
6.0 (6002) Windows Vista™ Business Service Pack 2
6.0 (6001) Windows Vista™ Enterprise Service Pack 1
6.0 (6001) Windows Vista™ Business Service Pack 1
6.0 (6000) Windows Vista™ Ultimate
6.0 (6000) Windows Vista™ Enterprise
6.0 (6000) Windows Vista™ Business
6.0 (5600) Windows Vista™ Ultimate
6.0 (5381) Windows Vista™ Ultimate
6.0 (5365) Windows Vista™ Ultimate Service Pack 1
6.0 (5365) Windows Vista™ Ultimate
5.1 (2600) Windows XP Professional Service Pack 3
5.1 (2600) Windows XP Professional Service Pack 2
5.1 (2600) Windows XP Professional Service Pack 1
5.0 (2195) Windows 2000 Professional Service Pack 4
5.0 (2195) Windows 2000 Professional Service Pack 3
5.0 (2195) Windows 2000 Professional Service Pack 2
5.0 (2195) Windows 2000 Professional Service Pack 1
5.0 (2195) Windows 2000 Professional
4.0 Windows NT

10.14.3 Mac OS X
10.8 (6) Mac OS X
10.6.8 (Build 10K549) Mac OS X

11 SLES Likewise Open unknown.unknown.unknown
2.6.18.8-ADEVM Linux CertifyDC 4.5.0-339:N:CDC
2.6.18-308.el5PAE Linux CertyfiyDC 4.6.0-124:N:CDC
6.0 Red Hat Enterprise Linux Server CertifyDC 4.5.0-357:N:CDC
6.0 Linux CertifyDC 4.6.0-113:N:CDC
6.0 Linux CertifyDC 4.5.0-339:N:CDC
5.8 (Final) CentOS
2.2.0.470.. Cisco Identity Services Engine
unknown unknown Likewise Open 6.2.0
unknown unknown Likewise Open 6.0.53010
unknown unknown Likewise Identity 5.3.0
I don't understand, really - what kind of smart decision was source of stupid characters in names of operating systems like (TM) and (C)? It's a kind of joke.