Next Tuesday – 26 July there will be a UK user group session looking at PowerShell remoting: cmdlets with remoting capabilities .NET remoting capabilities Invoke-Command PowerShell sessions WinRm and WSMan cmdlets Details on joining the live meeting session: When: Tuesday, Jul 26, 2011 7:30 PM (BST)Where: *~*~*~*~*~*~*~*~*~* A look at PowerShell Remoting using individual commands, […]
Archive for July, 2011
More information plus registration details from http://blogs.msdn.com/b/powershell/archive/2011/07/20/powershell-deep-dive-registration-info-amp-call-for-session-proposals.aspx The one in Vegas in April was brilliant. This is going to be better
The switch statement is used to make a choice when there are multiple possible answers. It is a more efficient answer than using lots of if statements. This problem from the forum gives a good illustration $sfiles = "c:\files\small" $mfiles = "c:\files\medium" $lfiles = "c:\files\large" Get-ChildItem -Path c:\test | foreach { $length = [math]::round(($_.Length /1kb), […]
PowerShell doesn’t have the equivalent of an SQL Union statement that lets you join objects together. What you can do is use New-Object to create the joined output. As an example that recently came up on a forum $outputs = @() Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPenabled=$true" | foreach { $nic = Get-WmiObject -Class Win32_NetworkAdapter -Filter […]
The question “Can I do X with PowerShell?” comes up very frequently. PowerShell provides access to a huge range of functionality: .NET COM WMI Microsoft and third party products Usually the answer is “Yes, you can” BUT What doesn’t seem to be considered so often is the question “Should I do X with PowerShell?” If […]
I was recently asked about getting the security settings for printers. $pace = DATA { ConvertFrom-StringData -StringData @’ 983052 = ManagePrinters 983088 = ManageDocuments 131080 = Print 524288 = TakeOwnership 131072 = ReadPermissions 262144 = ChangePermissions ‘@ } $flags = @(983052,983088, 131080, 524288, 131072, 262144) function get-printersecurity { [CmdletBinding()] param ( [string]$computer="." ) Get-WmiObject -Class […]
Using AccountManagement classes to set local accounts expiry
Posted by: richardsiddaway | July 15, 2011 | 2 Comments |This is a little more verbose than the WinNT example function set-expirydate { [CmdletBinding(SupportsShouldProcess=$true)] param ( [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string]$computer, [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string]$id ) BEGIN {Add-Type -AssemblyName System.DirectoryServices.AccountManagement} PROCESS { switch ($computer){ "." {$computer = $env:computername} "localhost" {$computer = $env:computername} } $ctype = [System.DirectoryServices.AccountManagement.ContextType]::Machine $context = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext ` -ArgumentList $ctype, $computer $user = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($context, […]
Setting expiry dates on AD accounts is a common occurrence and is well documented. Setting expiry dates on local accounts is also possible $user = [adsi]"WinNT://./Test1, user" $expirydate = (Get-Date).AddDays(2) $user.Put("AccountExpirationDate", $expirydate) $user.SetInfo() $user.RefreshCache() $user | Format-List * This uses the WinNT (remember its case sensitive) ADSI connector to get a local account. We then […]
To enable repeatable testing of the statistical functions I’m creating I decided to create a test script. $data1 = @(1,2,3,4,5,6,7,8,9,10) $data2 = @(21,22,23,24,25,26,27,28,29,30) get-mean -numbers $data1 get-mean -numbers $data2 get-standarddeviation -numbers $data1 get-standarddeviation -numbers $data2 get-correlation -numbers1 $data1 -numbers2 $data2 As it always uses the same values and calls the functions in the same way […]
This measures the degree of dependence between two sets of values – +1 indicates perfect positive correlation 0 indicates no correlation -1 indicates perfect negative correlation We can calculate the correlation coefficient using this function function get-correlation { [CmdletBinding()] param ( [double[]]$numbers1, [double[]]$numbers2 ) $count1 = $numbers1.length $count2 = $numbers2.length if ($count1 -ne $count2 ){ […]
Categories
- .NET
- Active Directory
- Architecture
- Azure
- Bash
- BITS
- Books
- CDXML
- CIM
- Cloud
- COM
- Containers
- Deep Dive
- Desired State Configuration
- DevOps
- DHCP
- DNS
- DSC
- European Summit
- Events
- Exchange
- File System
- Firewall
- General
- General IT Matters
- Hyper-V
- IIS
- Infrastructure
- IT Community
- IT Security
- Learning PowerShell
- Linux
- Math
- Microsoft
- Modules
- Nano Server
- Networking
- Office 2010
- Office 2013
- Open Source
- Opinion
- Outlook
- Philosophy
- PowerShell
- PowerShell 7
- PowerShell and .NET
- PowerShell and Active Directory
- PowerShell and CIM
- PowerShell and Exchange 2007
- PowerShell and IIS
- PowerShell and SQL Server
- PowerShell and WMI
- PowerShell Basics
- PowerShell original
- PowerShell Summit
- PowerShell User Group
- PowerShell User Group 2
- PowerShell v2
- PowerShell V3
- PowerShell v4
- PowerShell v5
- PowerShell v6
- PowerShell.org
- PowerShellGet
- PowerShellV2
- PSAM
- Rant
- Registry
- Scripting
- Scripting Games
- Scripting Games 2104
- Security
- SQL Server
- Storage
- Strings
- Summit
- Technology
- Uncategorized
- Virtualization
- Windows 10
- Windows 2012 R2
- Windows 7
- Windows 8
- Windows 8 Server
- Windows 8.1
- Windows Server
- Windows server 1709
- Windows Server 2008
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016
- Windows Server 2019
- WMFv5
- WPF
- WSUS