powershell

Any tips for T-SQL/Powershell code to automate failover for log shipping?

Given that I have to use log shipping and have a lot of databases that need to be failed over does anyone have any T-SQL/Powershell code for MS SQL Server 2005 that can automate that failover process as much as possible? These are the steps it would need to cover (or as many as possible): Attempt to backup the transaction log one last...

How do I concatenate strings with variables in powershell?

I'm trying to build a file path in powershell and the string concatenation seems to be a little funky. I have a list of folders: c:\code\MyProj1 c:\code\MyProj2 I want to get the path to a dll here: c:\code\MyProj1\bin\debug\MyProj1.dll c:\code\MyProj2\bin\debug\MyProj2.dll Here's what I'm trying to do: $buildconfig = "Debug" G...

Sync'd Hashtable not PowerShell display-friendly. Try: [HashTable]::Synchronized(@{})

I have an object coming from .Net that has a property of type SyncHashTable that can't be viewed w/o an exception being thrown. One-line repro: [HashTable]::Synchronized(@{}) Multi-line easier to play with repro: $ht = new-object hashtable $ht.add("foo", "bar") $hts = [Hashtable]::Synchronized($ht) $hts The error: format-default ...

How to user Powershell 'invoke-expression' to run an executable as a different user

I have a c++ service application that launches a Powershell script (powershell.exe script.ps1). In the script an executable is run but needs to be run with different user credentials. Is there a way to do this in Powershell with the invoke-expression cmdlet or some other way? ...

Powershell scripts don't work by default

So I wanted to get started with writing a powershell script. I wanted to start small and simply write a script that substiutes a local file folder as a drive. Pretty simple. I've done it before using the old DOS command tools. So the script I wanted to write is: subst d: G:\CER Ok, so I try to execute the script in the Powershell IS...

Determining if a Powershell command was successful

Hi I am quite new to Powershell but I have one niggling question. I want to be able to tell if a command has completed successfully so I can give meaningful messages to host. I am using the appcmd command to add a binding in IIS. Essentially that goes as follows: ./appcmd set site /site.name:........................ But how can I do a...

PowerShell CmdLet as Visual Studio External Tool

I am attempting to add a PowerShell cmdlet as an external tool in Visual Studio 2010, but whenever I call the external tool I get: {foo} cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details. I have already set my system's execution policy to 'Remote...

Mercurial color extension in Windows Powershell

Is there a way to enable color support for Mercurial in Powershell on Windows 7? The ColorExtension page says to add [color] mode = win32 to your .hgrc file, but it doesn't seem to make a difference. Running hg status shows several files that have not yet been added to the repository, and I believe they should have a pink color (bas...

Bash, Perl, or Powershell? For Jobs/General

Despite knowing a good bit of C++......i actually don't know that much about scripting languages. I feel like however I need to learn more about them. However there are a fair bit of different ones, but which one would be the best one to learn for a job? (I am a CS graduate in December btw) or just a general "better" to work with. Power...

Run a solution in debug mode if MSBuild compilation is successful from the command line

I am looking to improve my personal development process. I would like to create a batch file or similar that I can run from Windows PowerShell or the plain-old command line that does the following: Compiles my solution (e.g. C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe /m:8 "%CD%\MySolution.sln") If the compilation was successfu...

"Write-Error" (write in Powershell, used in C#) works BUT Write-Debug doesn´t work - Why?

Hello, I have written a program with C#, that creates a logfile and fills this by using log4net. This program starts powershell-scripts. The scripts use log4net, too. It works: > C#: > ps.Runspace.SessionStateProxy.SetVariable("myMethod",(Action<Level,string>)myMethod); > ps.AddCommand(System.IO.Path.Combine(pathScripts, testSkript...

How to attach a file to an email with PowerShell

I have written a PowerShell script that will create an email, however I can't seem to attach a file. The file does exist and PowerShell can open it, Could anyone tell me what I'm doing wrong? $ol = New-Object -comObject Outlook.Application $message = $ol.CreateItem(0) $message.Recipients.Add("Deployment") $message.Subject = "Website ...

Get-ChildItem and registry key access not allowed

I'm trying to do a simple PowerShell script to access the registry and I'm doing it like this: Foreach ($key in Get-Childitem HKLM:\SYSTEM\CurrentControlSet\Control\Class\"{4D36E972-E325-11CE-BFC1-08002BE10318}") { $key.name } There's a bunch of keys that are just digits (the ones I want) but then there's one named "Properties" wh...

Differences between powershell and ruby

I am new to the dynamic languages scene, and trying to find a good starting point. Looking at how Microsoft is diminishing the role of Iron Ruby in its offerings, I am looking around for a dynamic programming language that will be supported on dotNET platform. Could you list specific features that are found in one but not the other, to...

Little issue with New-ItemProperty in PowerShell

I'm new to PowerShell and I can't seem to find how to fix this after countless Google searches. I know it's probably easy, but here's basically what I want to do and the error that shows: PS C:\Windows\system32> $path = "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}" Get-Childitem $path -ErrorActio...

Windows powershell script triggered by PSExec is not killing Powershell process when it finishes running

I need to complete a series of tasks across several Windows 2008 servers that need elevated permissions and as such I've had to create a series of scheduled tasks that i'm running via psexec. Since they have to run in sequence, I found and modified a powershell script that 'stalls' until scheduled tasks are completed on remote machines. ...

Get IIS website into version control

The Problem: Until now, I create a IIS website/app using the IIS manager tool. The problem is that changes to a IIS website aren't documented as they should be. For example: when I update the URL Rewrite rules this changes should be documented in a version control solution. What is your solution to solve this issus? ...

In PowerShell is there a way to inspect and print the function name where the breakpoint hit in the action block?

Set-PSBreakpoint -Variable idx -Mode Write -Action { Write-Host -ForegroundColor Red "MyAction: $($idx)" } Function Test ($p) { 0..$p | % { $idx = $_ $idx } } Test 3 ...

How can I get a collection of the assemblies in my .NET solution?

Hi, For a .NET solution, is there a way to get all the .dll files for each project in the solution? For example, if I make an empty .NET solution (this is Visual Studio 2010 btw), and add 3 projects called "a", "b" and "c", and build each, providing me with dll's a.dll, b.dll, and c.dll, is there any code sample in either C# or Powershe...

PowerShell ForEach / Piping confusion

I am using the TFS PowerTools Cmdlets in PowerShell to try to get at some information about Changesets and related WorkItems from my server. I have boiled the problem down to behavior I don't understand and I am hoping it is not TFS specific (so someone out there might be able to explain the problem to me :) ) Here's the only command th...