powershell

powershell 2.0 try catch how to access the exception

This is try catch in powershell 2.0 $urls = "http://www.google.com", "http://none.greenjump.nl", "http://www.nu.nl" $wc = New-Object System.Net.WebClient foreach($url in $urls) { try { $url $result=$wc.DownloadString($url) } catch [System.Net.WebException] { [void]$fails.Add("url webfailed $url") ...

How to secure my connection string? powershell + xml

I store my connection-string in XML file. Then i use it in powershell script. Is there a way to secure it/to encrypt it somehow? ...

Updating Active Directory user properties in Active Directory using Powershell

In a Windows Server 2003 R2 environment, using Powershell v2.0, how would one duplicate the functionality of Set-QADUser to update user properties in Active Directory, like their phone number and title? The trick here being, I would like to do this without depending on Set-QADUser and I do not have the option to use the Server 2008's co...

How can I remove SVN directories after a confirmation prompt?

Hello, I want to be able to remove the .SVN folders from a directory. I found the following registry hack that will allow you to do just that... http://weblogs.asp.net/jgalloway/archive/2007/02/24/shell-command-remove-svn-folders.aspx However, the one thing I don't like about this solution is that it gives NO CONFIRMATION at all. I ...

Execute SqlPS Scripts from Asp.net

I would like to execute sqlps scripts from asp.net. With this article I was able to run simple powershell comannds but don't know how to invoke sqlps. Thanks, Fahad ...

Why does a form displayed by PowerShell sometimes not show up?

When I create a form (window) in PowerShell, I can usually display the form using .ShowDialog(): $form = New-Object System.Windows.Forms.Form $form.ShowDialog() .Visible is set to False before and after .ShowDialog(). But when I do a .Show() nothing is displayed on the screen: $form.Show() And .Visible is now set to True (presumab...

Strange behavior with Powershell scriptblock variable scope and modules, any suggestions?

NOTE: I'm using PowerShell 2.0 on Windows Vista. I'm trying to add support for specifying build arguments to psake, but I've run into some strange PowerShell variable scoping behavior dealing specifically with calling functions that have been exported using Export-ModuleMember (which is how psake exposes it's main method). Following i...

PowerShell remote sessions: Problems with ESET Nod32 AntiVirus

I am making my first attempts at using PowerShell remoting features. I've set up the "destination" server using the instructions in the help docs. But when I attempt to start a remote session (by executing an "Enter-PSSession servername1" command), it sits there for a long time, and eventually gives this error: Enter-PSSession : Conne...

PowerShell Remote sessions and scope question: Commands appear to run locally

Here's a sample script that attempts to create a remote session on a server, then use WMI to get a list of the server's IIS application pools, and list their names: function Test-Remoting { [CmdletBinding()] param ( ) begin { Enter-PSSession TestServer $...

SQLCMD, when called from Powershell, returns ExitCode == 1, even if successful

Hi everyone. I have a Powershell script that calls sqlcmd to run a sql script that backs up a database: function RunSqlScriptWithErrorMessage { param([string]$sqlServer, [string]$sqlUserName, [string]$sqlPassword, [string]$scriptName, [string]$errorMessage) $commandName = "sqlcmd" $startInfo = New-Object Diagnostics.Proces...

How to programmaticaly write to the current prompt line in Powershell

Is it possible to send text to the current prompt line? Something like the following: PS[10]> Get-Location c:/ PS[11]> Write-PromptLine "This text has been written by Powershell" PS[12]> This text has been written by Powershell| # | denotes the caret ...

Powershell: wirte value in a input type=file Form.

I have a input type=text inputboxes on a webpage i load and fill with values and click the submitbutton which works fine: $ie=New-Object -comobject InternetExplorer.Application $ie.visible=$true $ie.Navigate("https://myurl/test.html") while($ie.busy){Start-Sleep 1} $ie.Document.getElementById("field_firstName").value="Firstname" $i...

Powershell - Insert node between two others

Hi, I would like to insert a node between 2 others already existing. In my script, I receive a xml variable and I would like to update this one. Ex : <mapping ...> <INSTANCE .. /> <INSTANCE .. /> <CONNECTOR .. /> <CONNECTOR .. /> </mapping> the result should be : <mapping ...> <INSTANCE .. /> <INSTANCE .. ...

Get "Missing expression after unary operator '-'" when I try to run a Powershell script

When I try to run following command C:\Documents and Settings\BURE\My Documents\ibos\script>powershell.exe -NoProfile -WindowStyle Hidden & 'C:\Documents and Settings\BURE\My Documents\ibos\script\files_from_nomad.ps1' 1 I get following error Missing expression after unary operator '-'. At line:1 char:2 + - <<<< WindowStyle Hidden T...

How to prepend an element to an array in Powershell?

The Powershell code: $list += "aa" appends the element "aa" to the list $list. Is there a way to prepend an element? This is my solution, but there must be a way to do this in a single line. $tmp = ,"aa"; $tmp += $list $list = $tmp ...

How to create a PowerShell script to check if txt files have more than 1 row of text?

So I have alot of .txt files. I need for it to move txt files to a certain folder if they have more than 1 line. That is, Text text text Blah blah blah But leave it alone if it's just Text text text Any suggestions on how to do this? This is on Windows XP if that helps. Thanks! EDIT: Thanks John for your efforts. Figured out a w...

Powershell AuthorisationManager check failed

This is just a blank script. I have made the ExecutionPolicy unrestricted as this is just a developer machine. Is there anything I'm missing? I'm running this on a win 2003 server virtualised. cheers ...

Passing string included dollar signs to -Replace Variable

I am trying to replace a sentence in .config file using powershell. ${c:Web.config} = ${c:Web.config} -replace '$BASE_PATH$\Test\bin`$Test_TYPE`$\WebTest.dll' , 'c:\program Files\example\webtest.dll' Everytime I try to run the above code I get "Invalid regular expression pattern: $BASE_PATH$\Test\bin\$Test_TYPE$\WebTest.dll" ...

Inject command line arguments into psake

I would like to inject command line parameters into my psake build script like: .\build.ps1 Deploy environment="development" But psake will treat every argument as a Task and will answer "task does not exists" Is it possible to inject command line arguments in psake? build.ps1 --> Import-Module '.\psake.psm1' Invoke-psake '.\tasks.ps...

How to make powershell wait on event log entry?

I need to create a component in a larger pipeline that starts vpn service and waits for a connection to be established before proceeding. I'd like to do this with Powershell if possible. I imagine the logic flow being something like this, but the multithreading aspect is vexing me. create an event log handler start a service wait for a ...