PowerShell – Check For Matching Items In Seperate Arrays

$test1 = (1,2,3)
$test2 = (2,4,6)
$test3 = (1,3,5)
( ( $test1 + $test2 + $test3) | Group-Object |?{$_.Count -gt 1}).Values

Example outputs:

PS C:\> $test1 = (1,2,3)
$test2 = (2,4,6)
$test3 = (1,3,5)
( ( $test1 + $test2 + $test3) | Group-Object |?{$_.Count -gt 1}).Values
1
2
3
PS C:\>  

PowerShell Special Characters and Tokens (short-handing):
http://www.neolisk.com/techblog/powershell-specialcharactersandtokens

PowerShell – Registry & File System Access Control Lists (ACL) Creation

#
# File system:
# http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesystemaccessrule(v=vs.110).aspx
#
# Name of the user or group:
$objIdentityReference = [System.Security.Principal.NTAccount]("HOSTNAME\username")
# Rights to assign. List: http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesystemrights(v=vs.110).aspx
$objFileSystemRights = [System.Security.AccessControl.FileSystemRights]"Read,Write"
# Permission inheritance: None, ContainerInherit, Object Inherit
$objInheritanceFlags = [System.Security.AccessControl.InheritanceFlags]::None
# Propagation of permissions: None, InheritOnly, NoPropagateInherit
$objPropagationFlags = [System.Security.AccessControl.PropagationFlags]::None
# Allow or Deny:
$objAccessControlType = [System.Security.AccessControl.AccessControlType]::Allow
# Create new rule:
$objRule = New-Object System.Security.AccessControl.FileSystemAccessRule ($objIdentityReference, $objFileSystemRights, $objInheritanceFlags, $objPropagationFlags, $objAccessControlType)
$objACL = Get-ACL "C:\TestFolder"
# Add our new rule:
$objACL.AddAccessRule($objRule)
# Set the new permissions:
Set-ACL "C:\Path\To\Folder" $objACL

# Alternatively, create your rule list manually:
$AclRuleList = New-Object System.Security.AccessControl.DirectorySecurity
$AclRuleList.AddAccessRule($objRule)
$AclRuleList.SetOwner([System.Security.Principal.NTAccount]"Administrators")
# http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.objectsecurity.setaccessruleprotection(v=vs.110).aspx
$AclRuleList.SetAccessRuleProtection($true,$false) #isProtected,preserveInheritance

#
# Registry:
# http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.registryaccessrule(v=vs.110).aspx
#
# Name of the user or group:
$objIdentityReference = [System.Security.Principal.NTAccount]("HOSTNAME\username")
# Rights to assign. List: http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.registryrights(v=vs.110).aspx
$objRegistryRights = [System.Security.AccessControl.RegistryRights]::FullControl
# Permission inheritance: None, ContainerInherit, Object Inherit
$objInheritanceFlags = [System.Security.AccessControl.InheritanceFlags]::None
# Propagation of permissions: None, InheritOnly, NoPropagateInherit
$objPropagationFlags = [System.Security.AccessControl.PropagationFlags]::None
# Allow or Deny:
$objAccessControlType = [System.Security.AccessControl.AccessControlType]::Allow

# Create your new rule:
$objRule = New-Object System.Security.AccessControl.RegistryAccessRule ($objIdentityReference, $objRegistryRights, $objInheritanceFlags, $objPropagationFlags, $objAccessControlType)
$objACL = Get-ACL "HKCU:\TEST"
# Add our new rule:
$objACL.AddAccessRule($objRule)
# Set the new permissions:
Set-ACL "HKCU:\TEST" $objACL

# Alternatively, create your rule list manually:
$AclRuleList = New-Object System.Security.AccessControl.RegistrySecurity
$AclRuleList.AddAccessRule($objRule)
$AclRuleList.SetOwner([System.Security.Principal.NTAccount]"Administrators")
$AclRuleList.SetAccessRuleProtection($true,$false)

WMIC, WmiObject, CimInstance Formatting

wmic bios get serialnumber

Reference: http://support.microsoft.com/kb/558124

New formats:

Get-WmiObject -Class "Win32_SystemEnclosure" | Select-Object SerialNumber
# OR
Get-CimInstance -Class "Win32_SystemEnclosure" | Select-Object SerialNumber

Another type of Query:

Get-WmiObject -Query "SELECT * FROM Win32_ComputerSystem" -ComputerName .
# OR
Get-CimInstance -Query "SELECT * FROM Win32_ComputerSystem" -ComputerName .