How to load assemblies in PowerShell?

LoadWithPartialName has been deprecated. The recommended solution for PowerShell V3 is to use the Add-Type cmdlet e.g.: Add-Type -Path ‘C:\Program Files\Microsoft SQL Server\110\SDK\Assemblies\Microsoft.SqlServer.Smo.dll’ There are multiple different versions and you may want to pick a particular version. 🙂

How can I pass an argument to a PowerShell script?

Tested as working: #Must be the first statement in your script (not coutning comments) param([Int32]$step=30) $iTunes = New-Object -ComObject iTunes.Application if ($iTunes.playerstate -eq 1) { $iTunes.PlayerPosition = $iTunes.PlayerPosition + $step } Call it with powershell.exe -file itunesForward.ps1 -step 15 Multiple parameters syntax (comments are optional, but allowed): <# Script description. Some notes. #> param ( … Read more

Powershell Custom Object Confusion

When I do a Get-Member, it seems to just show one object. Get-Member shows information about the distinct types in the collection of inputs, which means that the first occurrence of each type is reported on, with subsequent occurrences skipped. In your case, both input objects are of type [System.Management.Automation.PSCustomObject], so Get-Member will report just … Read more

How do you run a SQL Server query from PowerShell?

For others who need to do this with just stock .NET and PowerShell (no additional SQL tools installed) here is the function that I use: function Invoke-SQL { param( [string] $dataSource = “.\SQLEXPRESS”, [string] $database = “MasterData”, [string] $sqlCommand = $(throw “Please specify a query.”) ) $connectionString = “Data Source=$dataSource; ” + “Integrated Security=SSPI; ” … Read more