powershell

Deploy PowerShell Exchange Cmdlets with site but without installing full Management Instrumentation

Is it possible to run web site for managing Exchange Recipients on a web-server, where only PowerShell is installed? I dont want to install full Exchange Management Instrumentation on web-server, I want to use only Microsoft.Exchange.Management.PowerShell.Admin snap-in. Can I use some dlls from Exchange Server bin folder? ...

Determine Users Accessing a Shared Folder Using PowerShell

Hi, I need to determine the users/sessions accessing a shared folder on a Windows XP (SP2) machine using a PowerShell script (v 1.0). This is the information displayed using Computer Management | System Tools | Shared Folders | Sessions. Can anyone give me pointers on how to go about this? I'm guessing it will require a WMI query, bu...

Test-Path behavior in Powershell

I'm trying to write a script in powershell to batch convert video files. The way I intend to use it is to go to some folder full of video files and run it. It uses a conversion program that can be run in "command-line mode" (named handbrake) and saves the converted files with "-android" appended to them before the file extension. For ex...

Renaming files to remove periods in Powershell

I have a list of files like this: Test.(file1)[text].txt Test.(file2)[text].txt Test.(file3)[text].txt I need to remove any "()","[]" and any ".", replace them spaces without changing the file extension. I've tried the following but it's not working: dir C:\scratch\*.txt | % { Rename-Item $_ ($_.basename -replace "\(", " "` -repl...

How to run a PowerShell script without displaying a window?

How is it possible to run a PowerShell script without displaying a window or any other sign to the user? In other words, the script should run quietly in the background without any sign to the user. Extra credit for an answer that does not use third party components :) ...

Use bat to start Powershell script

I have a batch file test.bat to start a powershell script: @pushd "C:\myscripts" powershell .\test.ps1 arg1 "arg2 with space" arg3 @popd The script test.ps1 (located at C:\myscripts) is a very simple one like: # just print out the arguments Write-Output ("args count: {0}" -f $args.length) $args Then I tried to start test.bat. I sho...

How to read XML file from web using powershell

When I connect to my HP ILO using the URL, http://ilo-ip/xmldata?item=All it is returning a XML file in below format. <?xml version="1.0" ?> - <RIMP> - <HSI> <SPN>ProLiant DL385 G1</SPN> <SBSN>ABCDEFG</SBSN> <UUID>123456789</UUID> </HSI> - <MP> <ST>1</ST> <PN>Integrated Lights-Out (iLO)</PN> <FWRI>1.82</FWRI> <...

Determine What Version of PowerShell is Installed?

Hi, How can I determine what version of PowerShell is installed on a computer, and indeed if it is installed at all? Thanks, MagicAndi ...

Determine If Solution Compiles using MSBuild and PSake

Hi, I have put together a PSake (v2.0) build script, and the script is setting the $psake.build_success property as true even thought the call to MSBuild fails. Can anyone advise me on how to alter the script so that the $psake.build_success property will correctly return false when the MSBuild call fails? My PSake build script is a...

PowerShell: passing blocks as parameters to functions

I will explain my question on an example. Let's have following code in C#: void A(Action block) { B(() => { Console.WriteLine(2); block(); }); } void B(Action block) { Console.WriteLine(1); block(); } void Main() { A(() => { Console.WriteLine(3); }); } The output of this code is: 1 2 3 Now, I want to write this code...

What determines whether the Powershell pipeline will unroll a collection?

# array C:\> (1,2,3).count 3 C:\> (1,2,3 | measure).count 3 # hashtable C:\> @{1=1; 2=2; 3=3}.count 3 C:\> (@{1=1; 2=2; 3=3} | measure).count 1 # array returned from function C:\> function UnrollMe { $args } C:\> (UnrollMe a,b,c).count 3 C:\> (UnrollMe a,b,c | measure).count 1 C:\> (1,2,3).gettype() -eq (UnrollMe a,b,c).gettype() True ...

powershell and console app output

Im trying to automate video conversion with powershell and ffmpeg tool. Ffmpeg have detailed output about video if called without all nessesary parameters. Usually it reports about error and display input file info if one specified. Ex I interactively executed such command: d:\video.Enc\ffmpeg.exe -i d:\video.Enc\1.wmv this is po...

PowerShell: an elegant way to create closures

Keith Hill explained me that blocks in PowerShell are not closures and that to create closures from blocks I have to call method .GetNewClosure(). Is there any elegant way to create closures from blocks? (e.g. create a wrapping function, an alias?, ...) Example: { block } ${ closure } # ??? ...

Python, PowerShell, or Other?

What are the advantages of Python, PowerShell, and other scripting environments? We would like to standardize our scripting and are currently using bat and cmd files as the standard. I think Python would be a better option than these, but am also researching PowerShell and other scripting tools. The scripts would be used to trigger pr...

PowerShell: Links to interesting sites or blog posts

In this question Alan posted links to interesting pages about PowerShell. I found also some interesting pages: http://channel9.msdn.com/wiki/windowspowershellquickstart/ (cheatsheet) http://technet.microsoft.com/en-us/library/bb978525.aspx (core reference) http://devcentral.f5.com/weblogs/Joe/archive/2009/01/05/powershell-abcs---k-is-f...

Launch an EXE from inside a PowerShell module

This, when run from the PowerShell console, launches Internet Explorer, just as expected: $ie_command = "C:\Program Files (x86)\Internet Explorer\iexplore.exe" &$ie_command If I put the same exact code inside a function within a module, it does nothing. And, yes, other code within the same function works properly, so it's not an issue...

powershell - launching local apps fast

I am building a kiosk type config script on low-spec hardware. At the end of the script, it runs the various apps for the user to interact with. I currently use a plain Invoke-Command "path\to\app.exe". I want to get the interface up and running as quickly as possible. I want to launch the apps asynchronous. I know there there is star...

Using .NET library from PowerShell

I have a PowerShell snap-in for manipulating a database. The snap-in itself is just a wrapper for the main library implemented in a separate .NET DLL all written in c#. I have registered both the snap-in and the implementation DLLs with the GAC using installutil.exe Whilst the snap-in works fine in PowerShell, I need to be able to acce...

PowerShell script - How to process result of executed command

I have a small script that copies files to a list of remote machines. In this script I use: Copy-Item "$AppLocation\$AppName" -destination "\\$MachineName\c$\" -force This can throw various types of errors. If this throws an error, I want to log the error to a file and then continue. My question is that I'd like to know what would be...

In Powershell, what's the best way to join two tables into one?

I'm fairly new to Powershell, and am wondering if someone knows of any better way to accomplish the following example problem. I have an array of mappings from IP address to host-name. This represents a list of active DHCP leases: PS H:\> $leases IP Name -- ---- 192.168.1.1 Apple 192.16...