powershell

Looking for powershell equivalent of specific awk command...

My google-fu's failing me again. The information is (probably) out there, but I can't find it. I know UNIX like the back of my hand, use cygwin etc. however with the increased availability of Powershell on servers, and (on production servers at least) the difficulty at getting cygwin in place, I'm attempting to pick up Powershell. If not...

In PowerShell, how do I test whether or not a specific variable exists in global scope?

I'm using PowerShell scripts for some UI automation of a WPF application. Normally, the scripts are run as a group, based on the value of a global variable. It's a little inconvenient to set this variable manually for the times when I want to run just one script, so I'm looking for a way to modify them to check for this variable and se...

Windows Powershell 2.0 - How can I read ODBC from a System DSN into Excel 2007 worksheet

I see in the Excel documentation the QueryTables collection and ODBCConnection object, but not how to use them in powershell. I want to create a new workbook with a single worksheet, connect to a System DSN (doesn't need login/passowrd), and run "SELECT * FROM someTable" and have the results go into the worksheet. Excel is 2007; powers...

Question about $profile.psextended

I found a powershell tip regarding $profile.psextended that returns all of the various Powershell profiles and their locations. Having never see that before I ran ($profile | get-member). psextended was not in the list of results. Having access to some very helpful MVPs on another site I asked how the psextended property was found. With...

Problem with dash symbol in powershell

I want to use dash symbol in xml node name but when i try to get that node it says something about unexpected token. <hudson.scm.SubversionSCM_-ModuleLocation> <remote>svn://svn.something.ru/testlib/trunk/SOAPUI/pmplatform/email</remote> </hudson.scm.SubversionSCM_-ModuleLocation> $xmlone = New-Object XML $xmlone.Load($scriptRoot+"\co...

Using Powershell on one computer to execute a Powershell script on another

This might be really obvious, since I'm kind of new to Powershell, but what's the best way to run a Powershell script on one computer that accesses another to run a Powershell script on that one? I'm using V2.0 if that matters. ...

How to give the path as a parameter or a variable in powershell

Hi All, I have written a powershell script. the code has paths related to only my PC. Now the same code cannot be executed by another person on his machine because the path is diff. Therefore please let me know a way where my code can work on all machines. ...

Powershell returning identical data each time through loop

I'm trying to write a small Powershell function that will return some summary data from some XML log files. I wrote a short summarizing function: function Summarize-Log( $log ) { $obj = New-Object Object $obj | Add-Member NoteProperty Date $log.lastwritetime $obj | Add-Member NoteProperty Passed ([xml](get-content $log)).suit...

How to remove extra space between columns in Powershell Format-Table

I'm converting some csv data to a file format that expects values a certain positions in a line. I thought I'd use format-table to accomplish this by setting the column widths. However, this adds an unwanted extra space between columns. Is there a way to remove the space or are there other formatting options that I could use? $format...

Running a function in PowerShell

I am new to PS and have been given a script to run. The first thing I do is type in c:\powershell\ir.ps1. This seems to work. Then after defining my clients directory I am supposed to be able to just type in functions such as "ir-n". This worked at the person's desk that showed me how to do it, but I get the following error: The ter...

Traverse ftp subfolders to get file sizes in C#

Hi all, Was wondering if you could point me at a right direction on how to achieve this... I'm currently working on an application that will check the filespace consumed in a remote FTP server that has folders, subfolders and files. I managed to get some information using System.NET via FtpWebRequest, FtpResponse, WebRequestMethods & ...

Scheduled powershell script not running dot sourced scripts...

I have a main script that is running other scripts and loading the variables from those scripts using dot sourcing. The script runs fine interactively but when I schedule it to run it does not run the scripts I am dot sourcing. Any ideas? ...

Insert checkbox and VBA code into Excel using Powershell

Hi gurus, I need help on how to include a checkbox into Excel and make a Msgbox appear saying "Hello" when it's ticked. That's not really what I need to do though, but I can find my own way from there. This should be done using Powershell. Just to get started. $missing = [System.Type]::missing $excel = New-Object -Com Excel.Applicatio...

Using systemdiagnostics.process to run background jobs in Powershell

I know Powershell has background job functionality with Start-Job, Wait-Job, etc., but is it possible to use the Process class from System.Diagnostics in .Net to achieve the same thing? If so, what would be the best way to do it/what advantages would it have over the default Powershell mechanism of running background jobs? ...

how to update a value for a xml node using powershell

Ex : Test How can I change the value of the node Test to Power Poweshell script I use: $configuration = "app.config" [xml]$xml = New-Object XML $xml.Load($configuration) $xml.selectnodes("/configuration/Test") = {"UST"} $xml.Save($configuration) ...

How to pull a range of failed services from a remote server after a reboot

Caveat: Without spiking the cpu while a Get-WmiObject call parses the whole event log to match my specified filter. Situation: I am working on a script that remotely runs some checks, then reboots a pc. I want it to check the health once the server reboots (after sleeping for some time) to make sure services that were supposed to start ...

using PowerShell to replace string that contains $ in the string

I am trying to use PowerShell do a simple find and replace. I use template text files and use $in front of values that need to be changed. Example (Get-Content "D:\test") | Foreach-Object {$_ -replace "`$TBQUAL", "DBO"} | Set-Content "D:\test" it should find the following line OWNER=$TBQUAL and make it look like this OWNER=DBO I am ...

Translate a Unix1Liner to PowerShell

I would like to translate the following Unix 1 Liner to PowerShell. Synopsis of the command: This command will search recursively form the PWD (pressent working directory) for any file with the extenstion .jsp, and look inside the file for a simple string match of 'logoutButtonForm'. If it finds a match, it will print the file name and...

Simplest way to get an interactive console for my app

I want a simple, interactive way to demo middle-tier features of my app which have not had a UI created yet. I want an interactive console. When my application (WPF but it shouldn't matter) boots up I would like to also start a console window. This window should run powershell (or ruby, or python, but preferably powershell) and have i...

Create remote powershell session in c#?

I'm very new to PS so I think I'm missing something basic here. I can do a remote powershell session like this... $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://remote.com/Powershell -Credential "Domain\Admin" I want the equivalent in C# ...