powershell

How do I efficiently transform a series of strings in powershell?

Suppose I have a large number of strings formatted something like: <tag>blah blahXXXXXblah blah</tag> I want to transform these strings into something like: blah blahZZZZZblah blah on a powershell command line. All instances of XXXXX get replaced by ZZZZZ in the transformation and the outer tags are stripped out. It isn't well-fo...

How can I get Windows Powershell Get-ItemProperty to only show the property I want?

When using powershell, sometimes I want to only display for example the name or fullname of a file. From what I can gather, the way to do this is by using Get-ItemProperty (alias of gp) and passing -n fullname, For example PS C:\Dev> gp . -n fullname Notably I want to use this in longer scripts combined with foreach and where, and so...

Problems with Excel automation in PowerShell

Hi fellows, I’m trying to automate the refreshing of data in my Excel Reports. Here the script: $ExcelApp = new-object -ComObject Excel.Application $ExcelApp.Visible = $false $ExcelApp.DisplayAlerts = $false $Workbook = $ExcelApp.Workbooks.Open("RefreshTest.xlsx", 3, $false, 5, $null, $null, $true) $Workbook.RefreshAll() $Workbook.Sav...

How do I change a file's attribute using Powershell?

I have a Powershell script that copies files from one location to another. Once the copy is complete I want to clear the Archive attribute on the files in the source location that have been copied. How do I clear the Archive attribute of a file using Powershell? ...

Command Line ( or equivalent) tools for .Net Development

Spending most of my time in Visual Studio and using all the IDE tools. I wish I could spend more time using either of the following. *the Command Window in VS *cmd *cygwin, minGW... *PowerShell. *scripts? What are your favorite and essential commands to type in, opposed to keyboard shortcuts or clicking around? ...

How to run MSBuild from Powershell without spawning msbuild.exe process?

I am considering running MSBuild from a Powershell script by tapping directly to the MSBuild assemblies (as opposed to looking up MSBuild install path and starting msbuild.exe as a child process). Has anyone done this? What would be the simplest, most straightforward way to run the build? Are there any pros/cons to either technique you'...

Benefits of developing MMC snap-ins instead of traditional GUI apps

What are the benefits of developing MMC snap-ins instead of traditional GUI apps? AFAIK the MMC snap-ins can be loaded remotely to control some server applications but I have never dived deep in this approach. What are the pros and cons of MMC snap-in approach over traditional Win Forms (or WPF) GUI applications? And btw lately PowerShe...

Is PowerShell a good upgrade for a batch file?

I package our server releases into zip files using a batch file (Windows), running the command-line version of WinZip. Previously we did this sort of thing "by hand" but I developed the process of automating it with a batch file. The batch file has become quite complicated because our product is complicated (i.e., Which sections are we ...

Why does Vista report that my Windows account not being in Adminstrators Role?

Under Windows Vista, when I check whether my current user account is in Administrators role, I am getting a negative, as shown in the following picture. Can anyone tell me why I am not in the Administrators role? When I do the check if I am in "Debugger Users" role, I am getting "True" Thank you. ...

Filtering and copying with PowerShell

In my quest to improve my PowerShell skills, here's an example of an ugly solution to a simple problem. Any suggestions how to improve the oneliner are welcome. Mission: trim a huge icon library down to something a bit more manageable. The original directory structure looks like this: /Apps and Utilities /Compile /32 Bit A...

Run PowerShell scripts without installing PowerShell?

Is there a way to bundle PowerShell such that I don't have to install it on the OS? Ideally I'd like to use it in my build process, but I want something that's self-contained; I don't want to rely on each client computer installing PowerShell. I'm thinking I'd build a console app that hosts a PowerShell environment, but bundles the Power...

Editing shortcut (.lnk) properties with Powershell

I've found a nasty VBS way to do this, but I'm looking for a native PoSh procedure to edit the properties of a .LNK file. The goal is to reach out to remote machines, duplicate an existing shortcut with most of the correct properties, and edit a couple of them. If it would just be easier to write a new shortcut file, that would work to...

Calling PowerShell scripts from unmanaged C++

Microsoft appears to be moving a lot of configuration and query capabilities to PowerShell (accessible from C# or managed C++), while deprecating and even removing older APIs (accessible for C or unmanaged C++). Those of us who have extensive unmanaged C++ programs that can't switch to managed C++ may have a need to call PowerShell cmdle...

How to normalize a path in PowerShell?

I have two paths: fred\frog and ..\frag I can join them together in PowerShell like this: join-path 'fred\frog' '..\frag' That gives me this: fred\frog\..\frag But I don't want that. I want a normalized path without the double dots, like this: fred\frag How can I get that? ...

What tutorial do you recommend for learning PowerShell?

I would like to learn PowerShell in my spare time. I already know a bunch of stuff in that line (Perl, Ruby, Python, bash, cmd.exe) so a tutorial leveraging that would be awesome. Also, since I am a software developer (C# mainly, but done some C, some C++, some Java etc.) I am looking for something not geared towards the usual "power ...

powershell : get-date.adddays incorrect?

What i'm trying to do is create a powershell script which gets a list of folders in a directory which is filtered by a regular expression screening out folder names with nnnnnnx31 or nnnnnnddd where n = alpha chars for the first 6 chararcts and the last 3 is either numbers of the static string x31. Next it screens if the files are 90 da...

powershell : has anyone tried to install powershell on windows 2000 server?

Has anyone tried installing powershell on a Windows 2000 server? I realize its not supposed to be installed on windows 2000 server and therefore not supported; however the vbscript that runs on it takes 3.5 days to complete which powershell could probably finish in lesser time. Nevertheless, I noticed it just requires .NET 2.0 to run. ...

PowerShell: Can you hook or intercept PowerShell execution of external applications?

I want to do some housekeeping before executing any external console applications (setting some environment vars). In my web research, it looks like overriding NotifyBeginApplication() in $host might do the trick. Unfortunately, I can't figure out how to do that. Here's essentially what I want to do... $host = $host | ` Add-Member ...

How do you modify existing SharePoint sites?

I often have customer requesting changing properties, like the version history setting on all document libraries on all existing sites on a farm. So far the best solution I have been able to think of is to script it in Powershell, test the script before I run it, and then pray that I have not overlooked something critical. Is there a be...

How do I move a file to the Recycle Bin using PowerShell?

By default when you delete a file using PowerShell it's permanently deleted. I would like to actually have the deleted item go to the recycle bin just like I would have happen via a shell delete. How can you do this in PowerShell on a file object? ...