powershell

Refresh $env:path in Powershell?

I have a PowerShell script that checks that a certain directory is on the PATH (by looking through $env:path). It appears that $env:path is loaded and locally scoped by each application on startup, and that scope is passed on to any child applications. So... if someone opens Firefox, downloads my program, runs it, gets a message that t...

C#, Powershell - Microsoft.Exchange.Management.PowerShell.Admin

I'm having troubles using the Microsoft.Exchange.Management.PowerShell.Admin on a server. The server is not the one running Exchange 2007, it's a remote server (in the same zone). I can't figure out how to add the Snapin for Powershell - Microsoft.Exchange.Management.PowerShell.Admin. Is it possible to just get the dll file from the Exch...

In Powershell how do I set a temporary environment avariable from a variable $var?

Typically, in Powershell you would use env:VARIABLE = "Some kind of value" But my issue is that I have the name of the variable in a string object. Powershell does not recognize it as a string object and uses the variable name as the name of the environment variable. For example, if I do this: $someVariable = "MY_ENV_VAR" env:$some...

Delete DIR recursevely if file match? (Powershell)

I was wondering if anyone knew how to delete a directory if it has a specified file in it? For example, if have this directory: PS C:\Users\mike> dir Directory: C:\Users\mike Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 9/17/2009 6:26 PM 6615 pic001.jpg -a-...

powershell v2 remoting - How do you enable unecrypted traffic

I'm writing a powershell v2 script that I'd like to run against a remote server. When I run it, I get the error : Connecting to remote server failed with the following error message : The WinRM client cannot process the request. Unencrypted traffic is currently disabled in the client configuration. Change the client conf...

How to get Hudson CI to execute a Powershell script?

I'm using Hudson version 1.324 for CI and have a couple of issues: Environment: - Windows Server 2008 - Powershell v1.0 - Hudson 1.324 running as a service - Hudson Powershell Plugin installed - Psake (aka. "Powershell Make/Rake" available from Github) 0.23 (All current/latest versions as of this initial post) I have a Powershell (PS) ...

How to obtain numeric HTTP status codes in PowerShell

I know of a few good ways to build web clients in PowerShell: the .NET classes System.Net.WebClient and System.Net.HttpWebRequest, or the COM object Msxml2.XMLHTTP. From what I can tell, the only one which gives you access to the numeric status code (e.g. 200, 404), is the last, the COM object. The problem I have is that I don't like t...

Calling WNetAddConnection2 from PowerShell

I am trying to directly call some Win32 API's from a PowerShell script. I managed to make WNetAddConnection work with the code below: $cp = New-Object Microsoft.CSharp.CSharpCodeProvider $cpar = New-Object System.CodeDom.Compiler.CompilerParameters $Code = @" using System; using System.Runtime.InteropServices; namespace Win32Api { ...

How to check if PowerShell snap-in is already loaded before calling Add-PSSnapin

I have a group of PowerShell scripts that sometimes get run together, sometimes one at a time. Each of the scripts requires that a certain snap-in be loaded. Right now each script is calling Add-PSSnapin XYZ at the beginning. Now if I run multiple scripts back-to-back the subsequent scripts throw: Cannot add Windows PowerShell snap...

Handling events with PowerShell?

How can you handle events thrown by .NET object using PowerShell v2? Can someone point me to a simple code sample? ...

How to get environment variable in 64 bit Windows?

Is there any way to retrieve the environment variable in 64 bit machine. I already have %abc% which returns me variable in 32 bit machine, but doesn't work in 64 bit. My Mistake: How can I get through command line not through programming language? ...

How do I do dir /s /b in powershell

I have a folder with 3 files and want the equivalent of dir /s /b in powershell. How do I do that? e.g. if the folder name is temp3 and it contains 3 text files - a.txt. b.txt, and c.txt, doing C:\temp3>dir /s /b gives me C:\temp3\a.txt C:\temp3\b.txt C:\temp3\c.txt How do I get the same result in powershell? ...

Should I use Powershell or CMD.exe for this?

What should I use to accomplish this task? CMD.exe? Powershell powerscript? Windows Script Host with VBScript or JScript? Task: transverse into every sub-folder of a folder if the subfolder has a folder name XXX, invoke certain commands ...

PowerShell: how to get detailed information about a WMI event?

I'm learning PowerShell 2.0 on Windows 7. My task is simple: I want to listen for a WMI event and then display some information about it. Here is what I'm currently doing: Register-WmiEvent -class win32_ProcessStartTrace -sourceIdentifier processStart Wait-Event It seems to work. Indeed, I get this when I start a process: ComputerN...

PowerShell: how to grep command output?

In PowerShell I have tried: alias | select-string Alias This fails even though Alias is clearly in the output. I know this is because select-string is operating on some object and not the actual output string. What can be done about it? ...

Running powershell script from explorer = execution policy error

In windows 7 final I've done: Set-ExecutionPolicy unrestricted In windows explorer, I select a script.ps1 file, select open with, put in c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe A powershell window flashes briefly with an error about execution policy. Scripts run fine from within powershell. How can I run them from wi...

How to use the HTML Tidy .Net DLL wrapper in PowerShell?

I'm trying to use the HTML Tidy .Net wrapper in PowerShell 2.0. Here is a working example using C# (TestIt.cs included in the wrapper distribution): using Tidy; Document tdoc = new Document(); I'm doing this in PowerShell: [Reflection.Assembly]::LoadFile("C:\Users\e-t172\Desktop\Tidy.NET\Tidy.dll") New-Object Tidy.Document I get t...

Check if user is not supposed to be in sharepoint

So I pieced together this little script to dump all users in Active Directory into all the groups that they belong to. This part works great. But as in most organizations, the people in the sales force move around. Now lets say I have 5 groups with one user in each group Region 1 (Mark) Region 2 (John) Region 3 (Matt) Region 4 (Liz)...

Powershell inside Visual Studio

Does anyone know of a way I can run a powershell within Visual Studio. By that I mean, have an interactive powershell prompt in a tool window? Kindness, Dan ...

Looking for a PowerShell script to compare two folders recursively

Just thought it would be nice to have one but my PS skills are not up to task. Anybody can share theirs? ...