Tag Archives: Com Object

New article on PowerShell Magazine: Use Shell.Application to display extended file attributes

My latest article on PowerShell Magazine is on how to use Shell.Application Com object to display extended file attributes in PowerShell. Because this is heavily dependent on the Windows version and localization this does present some challenges. The full article containing tips on how to use this class is available on PowerShell Magazine : Use Shell.Application to display extended file attributes

The following example will list the first three attributes using the Shell.Application object:

$com = (New-Object -ComObject Shell.Application).NameSpace('C:\')
$com.Items() | ForEach-Object {
 New-Object -TypeName PSCustomObject -Property @{
 Name = $com.GetDetailsOf($_,0)
 Size = $com.GetDetailsOf($_,1)
 ItemType = $com.GetDetailsOf($_,2)
 }
}

For more articles like this, have a look at the External Articles section of my blog, it contains all the articles I have posted on external sources such as PowerShell Magazine. The article posted on PowerShell magazine contains a link to my Get-ExtensionAttribute script in the TechNet Script Gallery.

Links in this Article
PSTip: Use Shell.Application to display extended file attributes
PowerShell Magazine
External Articles
Get-ExtensionAttribute
My entries in TechNet Script Gallery
Share

New article on PowerShell Magazine: Retrieve scheduled tasks using Schedule.Service COMObject

My new tip has been posted on PowerShell Magazine is on how to retrieve scheduled tasks using Schedule.Service Com Object using PowerShell. Using this object it is possible to retrieve information about scheduled tasks either on the local or remote system. The full article containing tips on how to use this com object and what the considerations are when using this object is available on PowerShell Magazine : Retrieve scheduled tasks using Schedule.Service COMObject

The following code will connect to the local system using the Schedule.Service Com Object, administrative permissions are required to run this code:

$Schedule = New-Object -ComObject "Schedule.Service"
$Schedule.Connect('localhost')
$Folder = $Schedule.GetFolder('\')
$Folder.GetTasks(1) | Select Name,Path,State

For more articles like this, have a look at the External Articles section of my blog, it contains all the articles I have posted on external sources such as PowerShell Magazine. The article posted on PowerShell magazine contains a link to my Get-ScheduledTask script in the TechNet Script Gallery.

Links in this Article
PSTip: Retrieve scheduled tasks using Schedule.Service COMObject
PowerShell Magazine
External Articles
Get-ScheduledTask
My entries in TechNet Script Gallery
Share

Test-ScheduledTaskFolder – Script in TechNet Script Gallery

In the TechNet Scripy Gallery I received the request if it was possible to create a function that can test if a certain folder exists in task scheduler. For this purpose I have created a new function: Test-ScheduledTaskFolder.

This function has two parameters, -ComputerName and -TaskFolder which can be used to identify if a scheduled task folder exists on a local or remote system. The script requires administrative permissions to be able to run because the Schedule.Service ComObject is used and administrative credentials are required to access this particular object.

Here are some examples of how to use this function to collect information about scheduled task folders:

.EXAMPLE   
Test-ScheduledTaskFolder -TaskFolder \Microsoft

Description 
-----------     
Tests if the \Microsoft folder exists on the local system

.EXAMPLE   
Test-ScheduledTaskFolder -ComputerName server01 -TaskFolder \Microsoft,\Microsoft\Windows\RAS

Description 
-----------     
Tests if the \Microsoft and \Microsoft\Windows\RAS folders exists on server01

.EXAMPLE   
'server01','server02' | Test-ScheduledTaskFolder -TaskFolder \CustomTaskFolder

Description 
-----------     
Uses pipeline to verify if the \CustomTaskFolder exists on server01 and server02

The complete function is available in the TechNet Script Library. To view this script or to participate in the discussions about this script either comment here or in the TechNet Script Library.

TechNet Script Library
My entries in TechNet Script Gallery
Test-ScheduledTaskFolder
Share

Get-ExtensionAttribute – Script in TechNet Script Gallery

Previously I blogged about listing extended file and folder attributes using the Shell.Application object in PowerShell in my List length and bitrate for mp3 files using Shell.Application article. As a result of that post I decided to write a function, Get-ExtensionAttribute, to properly and consistently be able to list extension attributes even when the locale or version of windows is different.

For this purpose I have created a dynamic parameter -ExtensionAttribute which retrieves all extension attributes available on the system it is run which can be selected and displayed. The function takes path names from either pipeline or as a single path or collection of paths.

.EXAMPLE
Get-ExtensionAttribute -FullName C:\Music -ExtensionAttribute Size,Length,Bitrate

Description
-----------
Retrieves the Size,Length,Bitrate and FullName of the contents of the C:\Music folder, non recursively

.EXAMPLE
Get-ExtensionAttribute -FullName C:\Music\Song2.mp3,C:\Music\Song.mp3 -ExtensionAttribute Size,Length,Bitrate

Description
-----------
Retrieves the Size,Length,Bitrate and FullName of Song.mp3 and Song2.mp3 in the C:\Music folder

.EXAMPLE
Get-ChildItem -Recurse C:\Video | Get-ExtensionAttribute -ExtensionAttribute Size,Length,Bitrate,Totalbitrate

Description
-----------
Uses the Get-ChildItem cmdlet to provide input to the Get-ExtensionAttribute function and retrieves selected attributes for the C:\Videos folder recursively

.EXAMPLE
Get-ChildItem -Recurse C:\Music | Select-Object FullName,Length,@{Name = 'Bitrate' ; Expression = { Get-ExtensionAttribute -FullName $_.FullName -ExtensionAttribute Bitrate | Select-Object -ExpandProperty Bitrate } }

Description
-----------
Combines the output from Get-ChildItem with the Get-ExtensionAttribute function, selecting the FullName and Length properties from Get-ChildItem with the ExtensionAttribute Bitrate

The complete function is available in the TechNet Script Library. To view this script or to participate in the discussions about this script either comment here or in the TechNet Script Library.

TechNet Script Library
My entries in TechNet Script Gallery
Get-ExtensionAttribute
Share

List length and bitrate for mp3 files using Shell.Application

I recently got the request how to list the Bit Rate and Length for mp3 files. These properties are not available when using the Get-ChildItem cmdlet, but can be revealed when using the Shell.Application ComObject.

$com = (New-Object -ComObject Shell.Application).NameSpace('C:\Music')
# Determine correct index for Bitrate and Length, change names based on installed locale on your system
for( $index = 0; ((-not $bitrateAttribute) -or (-not $lengthattribute)); ++$index ) {
 $name = $com.GetDetailsOf($com.Items,$index)
 if ($name -eq 'Length') {$lengthattribute = $index}
 if ($name -eq 'Bit rate') {$bitrateAttribute = $index}
}
$com.Items() | ForEach-Object {
 # Create custom objects so output can be manipulated easier, also allows for structered output
 New-Object -TypeName PSCustomObject -Property @{
 Name = $_.Name
 Size = $com.GetDetailsOf($_, 1)
 DateCreated = $com.GetDetailsOf($_, 4)
 Length = $com.GetDetailsOf($_,$lengthattribute)
 BitRate = $com.GetDetailsOf($_,$bitrateAttribute)
 } | Select-Object -Property Name,Size,DateCreated,Length,BitRate
}

Now the downside of using the Shell.Application object is that the index number for the attributes can be different in between language packs and Windows versions. The code here has been verified to work on En-Us but for other locales changes to the code will have to be made.

For more information in regards to the Shell.Application object please refer to the following MSDN article:
Shell.Application 

Share

New article on PowerShell Magazine: Get a list of all Com objects available

I recently wrote a short function to gather all available Com Objects from the registry and display the list of all objects using PowerShell. I wrote a short article on how this work on PowerShell Magazine, have a look at it here:

http://www.powershellmagazine.com/2013/06/27/pstip-get-a-list-of-all-com-objects-available/

The function is available for download in the Technet Scripting Gallery:

http://gallery.technet.microsoft.com/Get-ComObject-Function-to-50a92047

 

Share