Failed to set iTunes track properties using Powershell - powershell

I used to use vbscripts to automate tasks such as adding mp3, changing genre, comments for tracks in iTunes.
I am now trying to create powershell scripts to do the same. I can added mp3 to iTunes, but I failed to change the properties of the track.... I don't know what I've missed.... The following is a sample of the powershell codes to change the Genre and the error said the property "genre" does not exist.
$iTunes = New-Object -com "iTunes.Application"
$library = $iTunes.LibraryPlaylist
$iTrack = $library.addfile("c:\temp\test.mp3")
$iTrack.tracks.Genre = "test"
However, I can see the property using $iTrack.tracks | get-member
Genre Property string Genre () {get} {set}
Thanks to anyone who could help..

I found two ways (there's more) to set properties.
Force the track to an array and set the properties of the first item
#($iTrack.Tracks)[0].Genre = "test"
Set properties by item name (which is kind of occurred when the object you have is already the one you want to set)
$iTrack.Tracks.ItemByName('song name').Genre = "test"

Related

How can I access a shapes style and change it through PowerShell?

I am trying to change the style of a bunch of shapes in one document. I have looked at the available properties of the shapes I want to change by printing them out to an html file. I have used MSDN's documentation to do some more research on these properties but have so far not had any luck with it working. I am fairly new to PowerShell, so there may be something I am misunderstanding about accessing properties.
I came across this on Microsoft's website. I tried to do what they were doing, but kept coming back with errors like, "Add-Type : Cannot add type. The assembly 'Microsoft.Office.Core' could not be found," and "Unable to find type [Microsoft.Office.Interop.Word.WdPresetLineDash]," where I imagine the two are related. I tried adding the Assembly, but that didn't help either.
I have tried this:
Add-Type -AssemblyName Microsoft.Office.Core
# Open the document
$doc = $word.Documents.Open($input)
$shapes = $doc.Shapes
foreach ($shape in $doc.Shapes) {
if($shape.Name -like "Straight Arrow Connector*"){
$red = [Microsoft.VisualBasic.Information]::RGB(255, 0, 0)
$shape.Line.ForeColor.RGB = $red.ToArgb()
$shape.ShapeStyle = [Microsoft.Office.Interop.Word]::MsoPresetLineDash
}
}
I have also used the styles that are here, by doing something like this:
$shape.ShapeStyle = [Microsoft.Office.Interop.Word]::msoLineStylePreset1
However, I get the same errors.
I also noticed on the html printout of the properties for the shape, I have the following line:
System.__ComObject#{000209a0-0000-0000-c000-000000000046} ShapeStyle Property MsoShapeStyleIndex ShapeStyle () {get} {set}
Does this mean I should be using ShapeStyle(msoLineStylePreset1)?

SSDT: How to configure SchemaCompare Object settings in code

How to edit the SchemaCompare Settings in the SchemaComparison object?
$SchemaComparison = [SchemaComparison]::new( $SourceEndPoint, $TargetEndPoint )
$SchemaComparison.Options = $DeployOptions
I am particularly looking to Remove Database options, but the SchemaCompare settings do not appear to be accessible by code:
$SchemaComparison.Options.ExcludeDatabaseOptions #(not known property of the Options object)
$SchemaComparison.SettingsService #(not a known property)
How can I do in code what I can EASILY do from the SSDT compare UI?
I found the answer. There is an excludedObjects property hiding in the options object. It's an array of ObjectType enums:
$SchemaComparison.Options.ExcludeObjectTypes += [ObjectType]::Aggregates
$SchemaComparison.Options.ExcludeObjectTypes += [ObjectType]::ApplicationRoles
$SchemaComparison.Options.ExcludeObjectTypes += [ObjectType]::Assemblies
You can exclude any you want. The MSDN includes the list here:
https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dac.objecttype.aspx

PowerShell SMLets - Cannot Create an instance of an abstract class

I am using SMLets (A collection of cmdlets that work with System Center) for PowerShell to create an object of a class. I know I am not supposed to create objects of abstract classes, but I am not sure what other class I could possible select. I am trying to create a group in System Center Service Manager, and the class for a configuration item group as far as I can tell is the one I am entering...
My code is:
#Get the name of the class I want to create an object of and store it in a variable
$groupClass = Get-SCSMClass -Name "Microsoft.SystemCenter.ConfigItemGroup$"
#Return the variable stored to ensure this part is working (Debug purposes)
$groupClass
#Get the active status of an object and store it in a variable
$objStatus = Get-SCSMEnumeration -Name System.ConfigItem.ObjectStatusEnum.Active
#Return the variable stored to ensure this part is working (Debug purposes)
$objStatus
#Create the object stored in my class variable and modify the DisplayName and ObjectStatus properties.
New-SCSMObject -Class $groupClass -PropertyHashtable (#{DisplayName = "Test"; ObjectStatus = $objStatus;}) -Debug -Verbose
Once I got this code working my idea was to read from a csv file containing a list of all the groups and loop the creation process. However, I keep getting the error: "Cannot create objects of an abstract class"
Am I using the incorrect class to create a group? If so, what is the correct class to select? Is there a more efficient method to do this? Any ideas at all please share, thank you in advance :)

Regularly check a property of a SharePoint item with Powershell

I am using powershell to check, if a SharePoint I just added has changed. To do so, I first add the item via
$spFile = $spFiles.Add(...)
after that I regularly do this:
$spFile.Item["propertyName"]
The result is the same every time, even if I change the property in SharePoint. So I guess I have to refresh the item in Powershell. How can this be done?
You need to get the document library once again and then only you can get the changed value. It stores in cache, Something like this you need to do
$library = $web.Lists["DocumentLibrary"]
$spFiles= $library.Items | where {$_.FileSystemObjectType -eq "File"}
foreach ($spFile in $spFiles) {
$spFile.Item["propertyName"]
}

Read missing Word template from Powershell

I have a series of Word documents which link to templates which no longer exist. This is causing problems for users trying to open them. I can get a list of the documents, loop through each one, and set the tempalte to null. While this will solve the problem, I can't determine what the template was before I changed it.
In cases where the template is not available on open, Word will replace the attached template with Normal.dot(x). However, the template I'm trying find is located in the document's Tempaltes dialog. Both AttachedTempalte() and get_AttachedTemplate().Name return Normal.dot when I know the document in question has a different template listed in the Templates dialog in word.
I can access this in VBA, and it's fustrating to not be able to do this in PS. Can anyone see where I'm messing up?
$word = new-object -comobject "Word.Application"
$doc = $word.Documents.Open({document path})
$word.Dialogs(Microsoft.Office.Interop.Word.WdWordDialog.wdDialogToolsTemplates).Template()
Returns:
Missing ')' in method call.
At :line:1 char:15
+ $word.Dialogs(M <<<< icrosoft.Office.Interop.Word.WdWordDialog.wdDialogToolsTemplates).Template()
Working VBA:
Dim doc as Word.Document
Dim strTemplate as String
Set doc = Documents.Open(Filename:=filename, Visible:=False)
doc.Activate
strTemplate = Word.Dialogs(wdDialogsToolsTemplates).Template
After which I can see the template name and path I should see in strTemplate.
I checked the ps script and adding $doc.Activate doesn't seem to help. I also noticed that the interop and VBA do not use the same wdDialog. PS uses wdDialogToolsTemplates and VBA using wdDialogsToolsTemplates. I checked the assembly in PS with the following
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Word") | out-null
[Enum]::GetNames("Microsoft.Office.Interop.Word.WdDialogs")
and confirmed the correct option is wdDialogToolsTemplates.
In powershell you must use the [] brackets to specify types and then the :: to specify the type member, so your 3rd line of powershell code should look like this:
$word.Dialogs([Microsoft.Office.Interop.Word.WdWordDialog]::wdDialogToolsTemplates).Template()
See these blog posts about powershell enums: Jeffrey Snover or Richard Siddaway.
I am trying to do something similar and the main aim is not to store any code inside a Word document.
PowerShell
I made a tiny bit of progress with the PowerShell route but I can't find a way to extract the path from the dialog boxes.
$objWord = New-Object -ComObject "Word.Application"
$objWord.Visible = $True
$objDoc = $objWord.Documents.Open("C:\path\to\document.doc")
$objToolsTemplates = $objWord.Dialogs.Item([Microsoft.Office.Interop.Word.WdWordDialog]::wdDialogToolsTemplates)
$objDocStats = $objWord.Dialogs.Item([Microsoft.Office.Interop.Word.WdWordDialog]::wdDialogDocumentStatistics)
Now $objToolsTemplates.Show() and $objToolsTemplates.Show() both cause the GUI to display dialogs containing the path to the original (unavailable) template but I can't find any way to extract that information programatically. According to MSDN WdWordDialog Enumeration documentation both of the dialogs should have a Template property.
VBScript
In the end I had to go with VBS instead. The following code will give you the path of the original (unavailable) template. It's still a script at least.
Option Explicit
Const wdDialogToolsTemplates = 87
Const wdDoNotSaveChanges = 0
Dim objWordApp
Dim objDoc
Dim dlgTemplate
Set objWordApp = CreateObject("Word.Application")
objWordApp.Visible = False
Set objDoc = objWordApp.Documents.Open("C:\path\to\document.doc")
Set dlgTemplate = objWordApp.Dialogs(wdDialogToolsTemplates)
Wscript.Echo dlgTemplate.Template
objDoc.Close(wdDoNotSaveChanges)
objWordApp.Quit