powershell

Where to put PowerShell scripts?

(I can't believe I'm actually asking this, but I am out of brainpower for the day.) I just wrote my first serious PowerShell script, and I'm really happy with it. I plan to use it every day or so. I want to be able to call it from the Posh command line. I'll give it a verb-noun type name, but for now it's a simple .ps1 and not one of th...

Can PowerShell autoconvert error output into exceptions?

In my PowerShell script I'm calling some command line tools (not cmdlets) that may output error text and set errorlevel nonzero on error conditions. I'd like any error from any of these tools to abort my script. What's the best way to do this? Is there a way to have PowerShell automatically check $? and stderr after every command and t...

powershell / runspace in a thread

Hello ! I'm running the following code : RunspaceConfiguration config = RunspaceConfiguration.Create(); PSSnapInException warning; config.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out warning); if (warning != null) throw warning; Runspace thisRunspace = RunspaceFactory.CreateRunspace(config); thisRunspa...

Powershell: Leave item alone if regex doesn't match

I have a list of pdf files (from daily processing), some with date stamps of various formatting, some without. Example: $f = @("testLtr06-09-02.pdf", "otherletter.pdf","WelcomeLtr043009.pdf") I am trying to remove the datestamp by stripping out dashes, then replacing any consecutive group of numbers (4 or more, I may change this to 6...

Powershell SQLCMD

We were experiencing problems with Powershell and SQLCMD, when there was sapces in the -v parameter variable powershell wouldn't run the command. e.g. sqlcmd ... -v VAR="Some space" Has anyone experienced this before or know how to fix the problem? Thanks, B ...

SourceSafe backup script - best approach?

I was wondering what the best approach might be for creating a backup of my organisation's SourceSafe database, and moving it to a share on another server? Currently we have a scheduled job which runs a batch file, which in turn executes a PowerShell script. This Powershell script creates a backup file (using SourceSafe command-line arg...

Powershell Golf: Next business day

How to find next business day with powershell ? ...

Simple Powershell lastwritetime compare

I need a Powershell script that can access a file's properties and discover the LastWriteTime property and compare it with the current date and return the date difference. I have something like this... $writedate = Get-ItemProperty -Path $source -Name lastwritetime ...but I can not cast the lastwritetime to a "DateTime" datatype. It...

What is the right way to do error handling in PowerShell?

PowerShell is a weird mix of .bat and .NET. In .bat, you check errorlevel and stderr output from commands. In .NET, you catch exceptions. How do cmdlets return errors? Do they throw exceptions when they fail or do they set $? instead? Is this configurable? I also assume that .NET functions I call in PowerShell will always throw excepti...

PowerShell ISE WPF control in-lining

I have heard that the PowerShell ISE uses the same WPF text editor as VisualStudio 2010 and the Oslo IntelliPad. I know that you can extend this editor in VisualStudio by inserting your own WPF control into the editor's XAML file. My question now: Is this also possible with the PowerShellISE? Did anybody try to do this yet? ...

How to customize publication in ASP.NET?

Hi Guys, I'm working on a fairly new project and we started from scratch. So not only the web application itself needs to get developed, but also the whole process of publishing the site and configuring the web server etc. need to be done from scratch. This question might be more apropriate for serverfault, but that really depends on t...

How do I check if a file is under a given directory, in PowerShell?

I want to check if a file path is in a given directory (or one of its subdirectories), from PowerShell. Right now I'm doing: $file.StartsWith( $directory, [StringComparison]::InvariantCultureIgnoreCase ) but I'm sure there are better ways. I could do take $file.Directory and iterate over all .Parents, but I was hoping for something...

coming from bash, what windows scripting language to learn?

For work I am moving over to windows after being on linux for quite a while. I want to get some scripting skills going for administrative tasks in windows. I am quite good with bash, but bash's "libraries/tools" are missing a lot when it comes to windows. I see vbscript, wsh, powershell, cmd, jscript, etc and wondering what to learn, or ...

c# Powershell. Configure runspace using RunspaceConfiguration.Create

Hi, I'm trying to find out how the RunspaceConfiguration.Create() method call is used. I want to set the c# hosting up, in a manner that will enable any conceivable powershell script from executing from c# by ensuring all Cmdlets, Providers etc, are available. Looking at the powershell samples, sample 5, it's got the following. Runspa...

How to enumerate the domain wide policy setting for a specific group policy object in AD using WMI or powershell?

I would like to query the domain wide settings of a specific group policy object. How do I do that in Powershell or WMI? For instance I would like to know the value for the password policy setting 'Minimum password length' that is configured in the GPO for the entire domain. ...

Powershell, web services and object types

I'm new to using web services under powershell, so maybe I have a basic misunderstanding about something. I'm working with Microsoft's Reporting Services. Here is a repro script. $computer = "rptdev" $uri = "http://$($computer)/ReportServer/ReportService.asmx?WSDL" $reporting = New-WebServiceProxy -uri $uri -UseDefaultCredential -names...

command line to update svn folders

I have tried several things so far but haven't had much luck yet, what I'm attempting to do is to have a command line or powershell script that I can run once a day to make sure my numerous checked out projects are up to date. I know I would be looping through the directory folders inside my workspace, but when setting the variables I ha...

Powershell: how do you read & write I/O within one pipeline?

I'd like to be able to type quick, simple commands that manipulate files in-place. For example: # prettify an XML file format-xml foo | out-file foo This won't work because the pipeline is designed to be "greedy." The downstream cmdlet acquires a Write lock to the file as soon as the upstream cmdlet processes the first line of input...

Powershell output

I'm having a little issue with controlling output in ps. Here's the line of code in question; $result|sort-object cn | format-table -wrap -autosize If I append | out-file $logfile the last column of my output is truncated. Now I know that if I changed the width of my console session and run the script again, my output is fine, b...

Can I use PowerShell 1.0 to list processes along with their PIDs and Command Lines?

EDIT by OP: My question presupposed that PowerShell was the best tool for this job. There is a simpler way of achieving my goal. A friend just told me about: iisapp.vbs. It displays exactly the info I need without requiring PowerShell. I'm working with dozens of ASP.NET websites running locally and when I want to debug a particular...