powershell

How to filter a character stream from an application using PowerShell?

A powershell question: I want to extract each line in a character stream produced by an application that matches a certain pattern which in pseudo-code would be something like this: PS> <a_ps_command> <the_application_command_for_outputting_the_text_stream> | <my_filter > output_file.txt In my case the application is a CM-tool that outp...

PowerShell script to get network card speed of a Windows Computer

What is the PowerShell script to get the speed a specific Windows machine's network card is running at? I know this can be done with a WMI query based statement and will post an answer once I work it out. ...

In need of a Smarter Environmental Package Configuration

I am trying to set up a package template in SSIS, following the Wrox Programmer to Programmer book, SQL Server 2008 Integration Services: Problem - Design - Solution. I'm really liking this book even though it is 2008 and we're using SQL Server 2005. I've got a working package template that uses an Indirect XML package configuration to i...

How to stop Powershell insisting on one dash in parameters?

It seems that somebody has subtly changed the way that parameter switches are parsed on powershell. On some machines "split-path c:\x\y --parent" works. On some it fails. Can anyone tell me a) what causes the difference and b) how can I stop it? ...

Accessing TFS from Powershell

Hello I am new to PowerShell and I am trying to get branches from TFS and merge them using a PowerShell script. Unfortunately I am failing a first hurdle. I do have Visual Studio 2010 install on my local machine and can access the TFS server (also 2010) fine. I am running the script from my local machine and have the following lines...

Powershell - Splitting variable into chunks

I have written a query in Powershell interrogating a F5 BIG-IP box through it's iControl API to bring back CPU usage etc. Using this code (see below) I can return the data back into a CSV format which is fine. However the $csvdata variable contains all the data. I need to be able to take this variable and for each line split each colu...

powershell function output to variable

I have a function in powershell 2.0 named getip which gets the IP address(es) of a remote system. function getip { $strComputer = "computername" $colItems = GWMI -cl "Win32_NetworkAdapterConfiguration" -name "root\CimV2" -comp $strComputer -filter "IpEnabled = TRUE" ForEach ($objItem in $colItems) {Write-Host $objItem.IpAddress} }...

How can you set a time limit for a PowerShell script to run for?

I want to set a time limit on a PowerShell (v2) script so it forcibly exits after that time limit has expired. I see in PHP they have commands like set_time_limit and max_execution_time where you can limit how long the script and even a function can execute for. With my script, a do/while loop that is looking at the time isn't appropri...

Run powershell commands in C#

RunspaceConfiguration psConfig = RunspaceConfiguration.Create(); Runspace psRunspace = RunspaceFactory.CreateRunspace(psConfig); psRunspace.Open(); using (Pipeline psPipeline = psRunspace.CreatePipeline()) { // Define the command to be executed in this pipeline Command command = new Command("Add-spsol...

powershell missing member methods in array

Hi Guys I have (yet another) powershell query. I have an array in powershell which i need to use the remove() and split commands on. Normally you set an array (or variable) and the above methods exist. On the below $csv2 array both methods are missing, i have checked using the get-member cmd. How can i go about using remove to ge...

Powershell: resolve path that might not exist?

I'm trying to process a list of files that may or may not be up to date and may or may not yet exist. In doing so, I need to resolve the full path of an item, even though the item may be specified with relative paths. However, Resolve-Path prints and error when used with a non-existant file. For example, What's the simplest, cleanest ...

PowerShell: How to add XmlElement to a non-root element

I'm having trouble adding an XmlElement to a non-root element in PowerShell. Basically, given this xml: <clubs> <club name="boca" position="1"> <field>bombonera</field> <field>bombonerita</field> </club> <club name="racing" position="19"> <field>cilindro</field> ...

Can I use PowerShell with SQL Server 2005?

Hi guys, I know SQL Server 2008 has exposed some features to PowerShell as snapins. Now I want to know whether I can use PowerShell with SQL Server 2005? I guess the answer is NO, right? Thanks. ...

Using Powershell regex to find PHP strings like "<?php eval "

Hello, I've been trying to find a string in PHP that matches something like this: Currently I've tried something like this; <()\?php eval(^>> but it dosen't seem to get the string correctly. edit: I forgot to add that I need to grab all the text form "" and it spans multiple lines. ...

Powershell Select-Object from array not working

I am trying to seperate values in an array so i can pass them to another function. Am using the select-Object function within a for loop to go through each line and separate the timestamp and value fields. However, it doesn't matter what i do the below code only displays the first select-object variable for each line. The second sele...

PowerShell locking File....

I am trying to do something very simple in powershell Reading the contents of a file Manipulation some string Saving the modified test back to the file function Replace { $file = Get-Content C:\Path\File.cs $file | foreach {$_ -replace "document.getElementById", "$"} |out-file -filepath C:\Path\File.cs } I have tried Set-Cont...

Find multiple line spanning text and replace using Powershell

Hello, I am using a regular expression search to match up and replace some text. The text can span multiple lines (may or may not have line breaks). Currently I have this: $regex = "\<\?php eval.*?\>" Get-ChildItem -exclude *.bak | Where-Object {$_.Attributes -ne "Directory"} |ForEach-Object { $text = [string]::Join("`n", (Get-Conte...

Powershell: Setting values of a filtered array

Hi All I want to read in a csv file, filter it based on the values of two of the fields and set the value of another field. Here's a simple example of what I'm trying to achieve: c:\somefile.csv contents: firstField,secondField,thirdField 1,2,"somevalue" 2,2,"avalue" 3,1,"somevalue" #Import file into array $csv = Import-Csv c:\somefi...

Using Remove-Item with Credentials

I am attempting to use the Remove-Item cmdlet as part of an automation for a system. The files are stored on a server that requires elevated rights to perform the file deletion. I have access to a domain admin account that I use for such automation scripts. The code below will build the PSCredential object: $password = New-Object Sys...

Using Powershell to set user permissions in Reporting Services

I'm asking this because i'm a n00b when it comes to Powershell. How do i use Powershell to add a particular domain user or group to a specific reporting role in SSRS2005 (say the Content Manager or Browser role)? Is there a simple one or two line script to achieve it? Thanks! Note: this is definately programming related (not server a...