header image

Archive for January, 2015

Modifying text

Posted by: | January 31, 2015 Comments Off on Modifying text |

I needed to modify some text somewhere in a file. The file looks like this ##  start file This is some text.   I want to change something.   But not this. ##  end file   I was playing around with various options.  The simplest I found was this: £> $txt = Get-Content .\test.txt £> […]

under: PowerShell Basics

Testing for a hotfix

Posted by: | January 30, 2015 Comments Off on Testing for a hotfix |

KB3000850 – the November roll up for Windows 2012 R2 contains some very useful updates. I’ve installed it on some machines in my lab but not all. The update is huge so I’m installing it manually rather than through WSUS.   I need to test a remote machine to determine if the update  is installed. […]

under: CIM, PowerShell and CIM, PowerShell and WMI

Variable select

Posted by: | January 29, 2015 Comments Off on Variable select |

I was working on some code that  accesses a SQL database this afternoon. I only needed to pull back a single column from a single row but which column to pull back is variable depending on other data. That’s OK $query = “SELECT $colname FROM tablename WHERE x = ‘y’” Invoke-SQLcmd –server <server> –database <database> […]

under: PowerShell Basics

WMI errors

Posted by: | January 27, 2015 Comments Off on WMI errors |

Most PowerShell users will have done something like this: £> Get-WmiObject -ClassName Win32_ComputerSystem Domain              : WORKGROUP Manufacturer        : Microsoft Corporation Model               : Surface Pro 2 Name                : RSSURFACEPRO2 PrimaryOwnerName    : TotalPhysicalMemory : 8506093568   Or you can use a computername to access a remote system £> $computer = $env:COMPUTERNAME £> Get-WmiObject -ClassName Win32_ComputerSystem -ComputerName $computer […]

under: PowerShell and WMI

Unravelling lists of distinguished names

Posted by: | January 26, 2015 Comments Off on Unravelling lists of distinguished names |

There are a number of AD properties such as MemberOf and directrports that consist of a collection of distinguisednames.  Sometimes you need the  name  of the object rather than the distinguished name: function getname { [CmdletBinding()] param ( [string]$dn ) $name = Get-ADObject $dn | select -ExpandProperty Name return $name } Get-ADUser -Filter * -SearchBase […]

under: PowerShell and Active Directory

Filtering on if an AD property exists

Posted by: | January 26, 2015 Comments Off on Filtering on if an AD property exists |

There are times when you want to filter the results based on whether a user has an AD property set.  You could do this: Get-ADUser -Filter * -Properties Title | Where Title  | select Name, Title   However, that involves pulling back all of the users and then filtering. Not very efficient especially across the […]

under: PowerShell and Active Directory

Awkward file and folder names

Posted by: | January 21, 2015 Comments Off on Awkward file and folder names |

Spent some time today dealing with a situation where there were special characters – namely [ ] in folder a file names £> Get-ChildItem -Path C:\Test     Directory: C:\Test Mode                LastWriteTime     Length Name —-                ————-     —— —- d—-        21/01/2015     17:58            Awkward [One] d—-        21/01/2015     17:59            Simple One   Each folder has 3 files: File 1.txt […]

under: File System, PowerShell Basics

PowerShell Summit NA 2015 Agenda changes

Posted by: | January 18, 2015 Comments Off on PowerShell Summit NA 2015 Agenda changes |

We’ve had to make some minor changes to the Summit agenda – the revised schedule is shown on the event web site – http://eventmgr.azurewebsites.net/event/home/PSNA15

under: PowerShell, Summit

PowerShell Heroes 2015

Posted by: | January 18, 2015 Comments Off on PowerShell Heroes 2015 |

Powershell.org has announced the 2015 list of PowerShell Heroes- http://powershell.org/wp/2015/01/17/announcing-our-2015-powershell-heroes/   These are people who have made an outstanding contribution to the PowerShell community but have not been recognised in other ways (such as an MVP award)   Please join me in congratulating them

under: PowerShell

Event log dates

Posted by: | January 12, 2015 Comments Off on Event log dates |

You can use Get-EventLog to query the event logs on you system Get-EventLog -LogName System   One frequent task is to check if events occurred during a specific timespan. You may feel that you need to use a where-object filter to do this but there is a simple method. Get-EventLog -LogName System -After (Get-Date -Date […]

under: PowerShell Basics

Older Posts »

Categories