powershell

XPath Powershell query for a string

Hi, I'd like to know how to search for a string within an xml document. The object type is System.Xml.XmlNode.XmlDocument. The string can be anything with the document. I.e. attribute or element. I tried Select-Xml -Xml $xml -XPath "./Test" but got no results ...

Scripting remote control for IIS 7

My server is running on windows server 2008, IIS 7. My client is Windows server 2003 or Windows XP. I want to start/stop websites remotely. I easily managed to do it interactively using IIS 7 manager on my clients machines (cf http://blogs.iis.net/bdela/archive/2007/10/08/remote-administration-managing-iis-7-rco-from-windows-xp-2k3-and-...

powershell pass system.object[] without unrolling

any ideas on how I can pass the Get-PSCallStack with out having it unroll. It appears to be a system.object[] but from what i have read online they don't remain intact when passed and " unroll ". I tried placing a comma in front to prevent it but that did not work. function Pass-Callstack ([System.Object]$arg0) { Write-Host 'Start Pass-...

PowerShell Socket object different if created through function, vs. through the CLI

I have a function: function QuerySMTPServer ([string]$strSMTPServerName) { # open up a socket to the SMTP server $socket = New-Object System.Net.Sockets.TCPClient $socket.connect($strSMTPServerName, 25) $socket # output for testing # read response data (should be a line starting with 220; cf. RFC821) $stream = $...

Uninstall a program with PowerShell or VBScript

I tried using this code in this thread: http://stackoverflow.com/questions/113542/how-can-i-uninstall-an-application-using-powershell But it doesn't uninstall the product. I just get this back: __GENUS : 2 __CLASS : __PARAMETERS __SUPERCLASS : __DYNASTY : __PARAMETERS __RELPATH : __PROPERTY_COUNT...

Visual Studio - Post Build Event - Throwing Errors

I've got a nice power-shell driven post-build script that does some magic mumbo-jumbo for pulling all our plugins into the correct location after they're compiled and sorting out thier dependencies with the master-project of the solution. My problem is, occasionally when I do something stupid, I can end up in a state where my script can...

PSSession is not working in my Powershell script

When I run the lines below from a script the file ends up being created on my local machine. $cred = Get-Credential domain\DanTest Enter-PSSession -computerName xsappb01 -credential $cred New-Item -type file c:\temp\blahxsappk02.txt exit-pssession When I run each line individually from the powershell console the remote session is cr...

replace the first line of text from a file

I would like to copy a file from one location to another, and replace the first line of text with a string. I almost have the script complete, but not quite there.. (see below) # -- copy the ASCX file to the control templates $fileName = "LandingUserControl.ascx" $source = "D:\TfsProjects\LandingPage\" + $fileName $dest = "C:\Program F...

PowerShell UIAutomation script not returning expected result

[I have posted this question earlier in the PowerShell Technet forum, but without a response] I am attempting to change Windows XP Quick Launch settings (enable / disable it using PowerShell). Existing VBScript solutions rely either on Registry or SendKeys, so I thought that this would be feasible in PowerShell through UIAutomation. My ...

how to Save the State of an c# App with powerShell?

Hi! I have a C# program in which the user adds multiple objects an editing Panel. These objects are all represented as a classes. Now I want the user to be able to save the scenario, so it can be loaded again. for that I want to generate a Powershell script of each scénario , but my probléme is how to save diferent objects on Powershel...

Calling powershell function with parameter from .cmd or .bat file

Hi, I have written a powershell script which is a complete function taking parameters (e.g. function name (param) { } ) and below this is a call to the function, with the parameter. I want to be able to call this function in its .ps1 file, passing in the parameter. How would I be able to package a call to the function via a .bat or .cm...

Executing a Powershell function (which takes parameters) from Powershell commmand shell

Hi, I have a powershell script which is a function and takes parameters. From with the powershell command shell, how do I execute a function? It seems like it works differently for different users. ...

Why does invoking PowerShell from C# throw a System.Management.Automation.CommandNotFoundException?

I'm using this c#: public bool RunPowershell(string script) { RunspaceConfiguration runspaceConfig = RunspaceConfiguration.Create(); using (Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfig)) { runspace.Open(); using (RunspaceInvoke scriptInvoker = new RunspaceInv...

Script to install an application and redirect to an internal address.

I want to install a piece of software (MultipleIE: it allows you to installs IE 3.0 - 6) I want to install just IE6 then have the shortcut redirect to an internal site (Http://finance) Is there an easy way to do this with a simple script? (VB, PowerShell, etc.) Our Help Desk is not very helpful, and we have at least 20+ users who need ...

How to confirm completion of previous command in powershell

I have a simple powershell script that gets ran daily to compress and move some log files. How can i test that the command completes successfully before deleting the original log file. set-location $logpath1 & $arcprg $pram $dest_file $source_file Move-Item $dest_file $arcdir If the Move-Item completes ok i want to remove-item $sourc...

Cannot enable feature with feature receiver via PowerShell

Hi guys, I've got a problem where I can enable a feature the UI and everything works as expected through site settings, but if I try and enable the feature via powershell (which we are doing as part of a scripted deployment), I get the following: Enable-SPFeature : Failed to create receiver object from assembly "xxxxx, Version=1...

How to sign digitally with SHA-2 in PowerShell (NOT OpenSSL)

Hi, How can I sign digitally a string with SHA-2 by PowerShell script, not using OpenSSL? I know how to do it with OpenSSL, but I'm wondering if there is a way to do it with .Net classes. Thank you. ...

Listing all Files and Folder with Sizes for both

I would like help with a PowerShell script that does exactly what this one (I found on this site) does, except I have tried to add another column for the file size and I can't seem to figure that part out. I need one that does specific file extensions, but also if anyone knows how to get a FULL listing of every file and folder with thei...

Parsing a comma separated file using powershell

I have a text file which contains several lines, each of which is a comma separated string. The format of each line is: <Name, Value, Bitness, OSType> Bitness and OSType are optional. For example the file can be like this: Name1, Value1, X64, Windows7 Name2, Value2, X86, XP Name3, Value3, X64, XP Name4, Value3, , Windows7 Name4, Va...

passing path to SqlCmd within powershell script

Im trying to write a powershell script which will execute sqlcmd.exe to run a sql script. The script contains a SQLCMD variable which I want to pass in on the command line via sqlcmd's -v switch. The problem is that powershell is doing something weird when I pass a path as the value of one of my variables which in turn causes the SQL scr...