powershell

How to extract $lastexitcode from c# powershell script execution.

Hi, I've got a scipt executing in C# using the powershell async execution code on code project here: http://www.codeproject.com/KB/threads/AsyncPowerShell.aspx?display=PrintAll&fid=407636&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2130851#xx2130851xx I need to return the $lastexitcode and Jean-Paul...

Setting permissions on a MSMQ queue in script

Can anyone give me some pointers on how to set permissions on MSMQ queues in script, preferably PowerShell, but I'd use VBscript ...

Set-transport rule works on powershell but fails when using web interface

I have a powershell script that modifies transport rules. It works perfectly from powershell and I want to create a web interface so non-tech bods can edit transport rules (specifically, redirections) but when I try and run it from a .net website, the set-transportrule command seems to be ignored. The script is: $rule = "Redirect -> " +...

How do typed properties show up in an untyped DataTable in PowerShell?

The following PowerShell code loads a SQL result into a dataset: $sqlCommand = "SELECT A, B FROM TestTable" $connection = New-Object System.Data.OleDb.OleDbConnection $connectionString $command = New-Object System.Data.OleDb.OleDbCommand $sqlCommand,$connection $connection.Open() $adapter = New-Object System.Data.OleDb.OleDbDataAdapter ...

How to get all arguments passed to function (vs. optional only $args)

$args returns only optional arguments. How can I get all function parameters? ...

Cannot access a disposed object error on external class library call

Hi, I have a Windows Forms app that provisions user accounts in Exchange using Powershell and Exchange2007 cmdlets. There is only one form to this application that takes the information for the new user and then runs the Powershell commands. Like a good programmer, I just refactored the code and took all the Exchange and Active Director...

Change path separator in Windows PowerShell

Is it possible to get PowerShell to always output / instead of \? For example, I'd like the output of get-location to be C:/Documents and Settings/Administrator. Update Thanks for the examples of using replace, but I was hoping for this to happen globally (e.g. tab completion, etc.). Based on Matt's observation that the separator is de...

Run a simple command using PowerShell recursively on a directory

What's the fastest way using either DOS scripting or PowerShell to run this simple command on a directory and all its subdirectories: convert filename.jpg -resize 620x620 "R:\processed\filename.jpg" DOS Batch script for single directory: FOR %%a in (*.jpg) DO convert %%a -resize 620x620 "R:\processed\%%a" I want to run this recur...

Why @($null) is $false, but @($null, $null) is $true?

Curious, what is the idea behind this: @() -as [bool] # False @($null) -as [bool] # False @($null, $null) -as [bool] # True I would expect either False/True/True or False/False/False, but not False/False/True. ...

Better way to print object than Write-Host

I use Write-Host analyze objects, but some times it is hard to understand what the object actually is. Consider: Write-Host $null Write-Host @() Write-Host @($null, $null) Prints: # Actually it prints nothing I would like some thing like this: Null @() @(Null, Null) Any suggestions? ...

Powershell: Practical usage of $^ and $$?

I am wondering whether anyone came up with good use cases of the $^ and $$ automatic variables in Powershell. At the moment I am not seeing much use for them, at least from a programmer perspective. When using PS interactively and executing a long command you could use .$^ to repeat it and with $$ you could get the last argument, but .$...

Confused with -Include parameter of the Get-ChildItem cmdlet

From documentation: -Include Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. The Include parameter is effective only when the command includes the Recurse parameter or the path leads to the ...

Convert xargs Bash command to PowerShell?

I've got a simple Bash command to resize some images automatically on a low-traffic website using ImageMagick - I'd like to convert this to a PowerShell command so I don't have to install Cygwin on my webserver. Can anyone lend their PSh skills here? ls | xargs -I {} rconvert "{}" -resize 128x128\> "{}" ...

Can I get detailed exception stacktrace in PowerShell?

Runing such script: 1: function foo() 2: { 3: bar 4: } 5: 6: function bar() 7: { 8: throw "test" 9: } 10: 11: foo I see test At C:\test.ps1:8 char:10 Can I get a detailed stack trace instead? At bar() in C:\test.ps1:8 At foo() in C:\test.ps1:3 At C:\test.ps1:11 ...

find the 10 largest files within a directory structure

How could one find the 10 largest files in a directory structure? ...

What objects are suitable for Add-Member?

Documentation states: Adds a user-defined custom member to an instance of a Windows PowerShell object. What "Windows PowerShell object" stands for? This works fine: $obj = new-object system.object $obj | add-member -membertype noteproperty -name Name -value "OK" $obj.name But this does not: $obj = @{} Actually, I am tryi...

Error retrieving registry value with Powershell

I'm attempting to read a value from a registry entry with Powershell. This is fairly simple, however, one particular registry key is giving me trouble. If I run the following, I can't get the value of the (default) of "$setting". C:\Program Files\PowerGUI> $setting = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\Curren...

set property syntax in Powershell

I am new to PowerShell, I am trying to change a property of an IIS website using the following syntax (which doesn't work) (get-item 'IIS:\Sites\Default Website').logFile.directory = 'd:\' It doesn't show any error but doesn't change the property either. Anybody help? ...

Recommended solution for scripting file operations over WebDAV?

I have a task: files available over WebDAV on a remote server (SSL required) must be checked for whether they may have been updated recently, and if so copied to a local folder. There are a number of other actions that need to be performed after they arrive (copied to other folders, processed, etc.). The operating system I'm working from...

Connect to wireless network

I have created a couple of PowerShell scripts which configure computers used in a training class. Some classes need to connect to a different wireless network (SSID). I can just instruct users how to use the windows XP facilitites to change the network they are connected to but I would like to be able to roll the network selection in t...