powershell

passing parameters to powershell from c#

Hi, I'm trying to pass a parameter to powershell from c# web app, but keep getting an error Reason = {"The term 'Param($ds)\r\n\r\n$ds\r\n\r\n\r\n' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try aga...

Powershell script cannot get applications list data from windows 7 machine.

Hi Everyone, Recently, I made a script to list all the installed applications in local & remote machine & give the output in a structured manner in a excelsheet. It looks like this: $a = Read-Host "Enter machine name" | Out-File -filepath C:\machine.txt $computerName = Get-Content C:\machine.txt $a = New-Object -comobject Excel.Appli...

Writing a script with the cmd prompt.

I'm trying to make a script that will place a list (in a .csv file) of processes that are running that take up more than 10 mb of RAM and shows the time + date the script was run. My teacher did this during his lecture but I can't remember how he did it. Just trying to figure out how to be better at IT. So my question is, can anyone hel...

Powershell to manipulate host file

Hello, I am looking at to see if I can create powershell script to update the contents in the host file. Anybody know if there are any examples that manipulate the host file using powershell or any other scripting lanaguages? Thanks. ...

How to split long commands over multiple lines in PowerShell

How do you take a commmand like this in PowerShell and split it across multiple lines: &"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" -verb:sync -source:contentPath="c:\workspace\xxx\master\Build\_PublishedWebsites\xxx.Web" -dest:contentPath="c:\websites\xxx\wwwroot\,computerName=192.168.1.1,username=administrator,password=xx...

Does Powershell support constants?

I would like to declare some integer constants in Powershell. Is there any good way to do that? ...

How to run a powershell script within a DOS batch file

How do I have a powershell script embedded within the same file as a DOS batch script? I know this kind of thing is possible in other scenarios: Embedding SQL in a DOS batch script using sqlcmd and a clever arrangements of goto's and comments at the beginning of the file In a *nix environment having a the name of the program you wish ...

How to suppress quotes in Powershell commands to executables

Is there any way to supress the enclosing quotation marks around each command-line argument that powershell likes to generate and then pass to external executables for command line arguments that have spaces in them? Here's the situation: One way to unpack many installers is a command of the form: msiexec /a <packagename> /qn TARGETDI...

Read multiple tables from dataset in Powershell

I am using a function that collects data from a SQL server: function Invoke-SQLCommand { param( [string] $dataSource = "myserver", [string] $dbName = "mydatabase", [string] $sqlCommand = $(throw "Please specify a query.") ) $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server=...

Invoke PowerShell script from c# in runspace and get line number where error occured

I have some PowerShell hosts in C# from where I execute PowerShell script code. The code below is from a host in an Add0In for Visual Studio. Problem is that if an error occurs in the PowerShell script code that I don't know the file and line number of the PowerShell script file where the error occured. My hosting code looks like: ...

Powershell IIS7 Snap in Assign SSL certificate to https binding

As part of our automated build procedure we are trashing and reconstructing our IIS site with powershell scripts. Once i have created the AppPool and the website complete with binding information I want to set the SSL certificate for the https binding. I can't find any concrete examples onl;ine anywhere that demonstrate this. Any ideas...

Invoking powershell from Java

Anyone know of a good library to invoke powershell scripts from within Java? I'm currently spawning a seperate process (powershell.exe) and then parse the output, but it would really be nice if I can leverage Powershell's 'power' by getting objects back from a powershell call. Edit: Otherwise, anyone else doing such interop? What metho...

Setting ForceCheckout on an SPList

I'm trying to set the ForceCheckout property on an SPList item and it's just not taking. I'm calling the Update() command as required. All it should take, in essence, is the following two lines. $myList.ForceCheckout = $false $myList.Update() Any ideas why this isn't working? It's remains $true no matter what. ...

Automating telnet with powershell

Ok, it's little convoluted. I am trying to write a script to automate telneting to a machine, execute few commands, look at the output in the telnet window, based on the output, send few more commands. Thanks for any help ...

How do I write a powershell script that gets the file with the most recent last write time from a folder?

The subject line says it all. I'd also like to do this using pipes. I figured that I could use Get-ChildItem, Measure-Object and Where-Object, but Measure-Object doesn't like dates. Should I have a script block which loops through each item returned from Get-ChildItem and does a comparison to see if it's the most recent? I thought that...

How to troubleshoot a 'System.Management.Automation.CmdletInvocationException'

Does anyone know how best to determine the specific underlying cause of this exception? Consider a WCF service that is supposed to use Powershell 2.0 remoting to execute MSBuild on remote machines. In both cases the scripting environments are being called in-process (via C# for Powershell and via Powershell for MSBuild), rather than 's...

Programmatically access document properties for Word 2007 documents

Is there a way in which I can programmatically access the document properties of a Word 2007 document? I am open to using any language for this, but ideally it might be via a PowerShell script. My overall aim is to traverse the documents somewhere on a filesystem, parse some document properties from these documents, and then collate ...

Powershell to analyse logs

I have loads of logs on a network drive X: I have a list of names in a text file say with this syntax DOE, John Daniels, Mary etc.... I want to script something that will read each line and scan my X: drive to find occurences of for example DOE, John and either write to a log or print to screen, sorted by date/time etc. Any ideas? Che...

Social Media Aggregator, Global Update via Powershell

Does anyone know of a way to interface with a Social Media Aggregator using Powershell. For Instance, I would like to update my global status on digsby using Powershell. Digsby would then fan the message out to Facebook, Myspace, Twitter, Etc.. I am open to using any Social Media Aggregator that can do this.. Digsby, Seesmic, Ping.fm Tw...

Tabexpansion function Does Not Resolve Variable

I'm attempting to override and implement my own TabExpansion. In the function I want to parse the contents of $psise.CurrentFile.Editor.Text when a certain $lastword criteria is matched. The issue I have is that the variable $psise.CurrentFile.Editor.Text is resolved to the contents of my TabExpansion function rather than whatever text i...