powershell-v2.0

Accessing wcf web service with powershell2

I'm trying to write a cmdlet that accesses one of my wcf webservices. I've been looking at the new cmdlet : New-WebServiceProxy, but it only really seems capable of consuming ASMX webservices. I've seen this article; which is focussed around Powershell v1.0 I'd rather use a better method (if one exists). http://keithhill.spaces.live.co...

PSExec never completes when run inside start-job

I'm trying to execute a cmd file on a list of 48 computers. I don't want to execute and wait for completion sequentially because each cmd takes about 10 minutes to complete. WinRM isn't an option. Neither is WMI. PSExec is an option....but I can't seem to make it work inside of Start-Job. I'm doing something like: $sb = { param...

[powershell] Concisely parsing a pipe

I have lots of text output from a tool that I want to parse in Powershell 2.0. The output is nicely formatted so I can construct a regex to pull out the data I want using select-string. However getting the subsequent matches out of select-string seems long-winded. There has to be a shorter way? This works: p4 users | select-string "...

PowerShell Add-PSSnapIn from an advanced (cmdlet) function

Hi, I would like to create an advancedmodule with a cmdlet function which performs some logic and adds some pssnapins. This is the code: function Add-DefaultSnapIns { [CmdletBinding()] param() begin {} process{ # ... Add-PsSnapIn SnapInName } end {} } export-module -function Add-DefaultSnapIns If I invoke the function from an...

Powershell 2 ISE, not stopping on breakpoints in imported modules

When we set breakpoints within a Module we've imported the debugger ignores the breakpoint. Has anybody else seen this behaviour? This is driving me nuts, we use PowerShell Modules extensively. The thing that's really weird is I can see the breakpoint if I run get-psbreakpoint PS H:\Projects\Powershell> get-psbreakpoint | format-list -f...

Long Running Powershell Script Freezes

Dear PowerShell users of SO, We are using a long running PowerShell script to perform a lot of small operations that can take an extremely long amount of time. After about 30 minutes the scripts froze. We were able to get the scripts to start running again by pressing Ctrl-C which caused the scripts to resume execution instead of killin...

How to create new com object with parameters using powerhsell?

Hi, I have COM object with few constructors, i'm trying to create new instance and passing parameters to the constructor using powershell 2.0, but i'm getting this error: Parameter set cannot be resolved using the specified named parameters. This is the code: $paramsInfo = New-Object -ComObject 'MyObject.ObjectA' $comObj = New-Object ...

Restart IIS6 application pool - ADSI error

Not sure what the eff' is wrong! I am using Powershell 2.0 on Windows 7. Had this same script working on Windows XP , am i just missing something? $server = "server1-vm1.prod.ds.russell.com" $name = "Superduper_Reports" $iis = [ADSI]"IIS://$server/W3SVC/AppPools/$name" $iis.psbase.invoke("recycle") Error (that invoke looks okay to me...

Get File Version and Assembly Version of DLL's in current directory and all sub directories.-

Good afternoon, I would like to be able to get the file version and assembly version of all DLL's within a directory and all subs. I'm new to programming and I can't figure out how to make this loop work. I have this for the assembly version (taken of a forum) $strPath = 'c:\ADMLibrary.dll' $Assembly = [Reflection.Assembly]::Loadfile...

PowerShell -as Family of Parameters

How can I find or list PowerShell's -as family of parameters? So far I found -as Type e.g. -as[Int] Also I have found -asHashTable My questions is what other -as parameters are available? ...

Copy-item create directory on single file copy

I'm trying to copy a single file using copy-item to a remote computer using powershell. It works fine if the directory already exists but fails if it doesn't. I know -force works if it is a directory to a directory but fails if it's a single file. Is there a way to get copy-item to create the destination path without doing a test-path...

PowerShell InvokeMethodOnNull Exception, but runs in PowerShell ISE?

Hello, some problem with a PowerShell script. I want to use the script to download a newspaper everday day using the Windows XP task manager. I scipt the code in PowerShell ISE and it works fine. But when i try to run the code in a normal powershell instance i get following exception caused by this piece of code $ie2.Document.getEle...

Powershell: Setting anonymous user in IIS6

I'm using the PowerShell script below to set anonymous user identity and authentication methods on an IIS6 server. The script seems to work at first, but if I issue an iisreset after running it the values revert to the old ones! How do I persist them? $server = "localhost" $siteName = "www.mysite.com" $iis = [ADSI]"IIS://$server/W3SV...

Is scriptblock parameter evaluation different for compiled cmdlets and advanced functions?

In experimenting with scriptblocks, I was attempting to use a scriptblock parameter with an advanced function and noticed that it performs differently than when supplied to a compiled cmdlet. In reviewing this blog post from the PowerShell Team blog, it appears that the PowerShell engine should be evaluating the scriptblock if a scriptb...

PowerShell removing console message colors when using tee-object

Is there any way to stop PowerShell from removing console message colors when using tee-object? When I run without tee-object I get the nice error and verbose powershell message colors like this: powershell.exe -noprofile -file $project_root/test_main.ps1 However, when I'm using tee-object (b/c I want logging to console & file), th...

Hide output of cmd command inside powershell.

Hello all, When set up of remote PowerShell session is impossible for me I'm using the psexec tool for launching scripts remotely. I'm asking for correct exit code of psexec in loop. Syntax of psexec which I'm using is this: ./psexec.exe \$Hostname -u $Username -p $Password -i ("c:\something.bat") Is there any possibility to hide output ...

Remove headers from Powershell Datasets

I need to remove the headers and spacing from a SQL dataset in Powershell so i can compare the result. Using $res = $DataSet.Tables[0].rows | ft -HideTableHeaders removes the headers but leaves the spacing. What is the best way of just showing the result prptySwitch ----------- False $SqlCmd = New-Object System.Data.SqlClient.SqlCo...

Running powershell scripts from within a .NET windows app

I'm needing to run scripts from within a vb.net windows app. I've got the scripts running in the background fine; Using MyRunSpace As Runspace = RunspaceFactory.CreateRunspace() MyRunSpace.Open() Using MyPipeline As Pipeline = MyRunSpace.CreatePipeline() MyPipeline.Commands.AddScript("import-module -name " & module...

Having problems with Powershell ConsoleShell.Start

Running the following code resulting in an HostException; Public Sub RunPowershellInConsole(ByVal scriptText As String) Dim config = RunspaceConfiguration.Create Dim args() As String = New String() {scriptText} ConsoleShell.Start(config, "Windows PowerShell", "", args) End Sub . System.Management.Automation.Host.Host...

data structure for powershell script

I am trying to write a powershell script that will take in a text file (or xml file or whatever I want ti to be) with a list of servername and some service names on that server to stop. I can get powershell to read in a line from a text file, but I can't figure out how to get powershell to import the data into seperate variable for me ...