header image

Archive for July, 2011

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, […]

under: PowerShell User Group

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

under: Deep Dive, PowerShellV2

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), […]

under: PowerShell Basics

Joining objects

Posted by: | July 18, 2011 | No Comment |

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 […]

under: PowerShell and WMI

Can I? Should I?

Posted by: | July 17, 2011 | No Comment |

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 […]

under: Philosophy, PowerShellV2

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 […]

under: PowerShell and WMI

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, […]

under: IT Security, PowerShell and Active Directory, Windows 7, Windows Server 2008, Windows Server 2008 R2

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 […]

under: IT Security, PowerShell and Active Directory, Windows 7, Windows Server 2008, Windows Server 2008 R2

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 […]

under: Math, PowerShellV2

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 ){ […]

under: Math, PowerShellV2

« Newer Posts - Older Posts »