powershell

C# Powershell setting the Console File

Hello, I was wondering if anyone knew how to use a console file in c#. I tried to run the command through pipeline: "powershell -PSConsoleFile \"C:\Program Files\Microsoft\Exchange Server\Bin\exshell.psc1\" -noexit -command \". 'C:\Program Files\Microsoft\Exchange Server\Bin\Exchange.ps1'\"" The issue that I run into is that it brings ...

How can I dispose SharePoint objects safely in PowerShell functions?

What is the proper way of disposing objects created inside a function? I came across this method on a website. function get-spweb ([String]$webUrl=$(throw 'Parameter -webUrl is missing!')) { $site = get-SPSite $weburl return $site.OpenWeb() $site.Dispose() } Does the Dispose method ever get called in this function? ...

PowerShell passing parameter to executable having switches.

Hi, i am tring to convert abc.exe /u "c:/programs/abc.dll" to powershell script can anybody explain how to do it. how can i execute the *.exe having switches with parameters?? thanks.. Sunny ...

Send Text in Clipboard to Application like Notepad (C# or Powershell)

I want to be able to send the text on the clipboard, in Windows, to an application. For example, I'm working on a text file in notepad, and I want to copy a portion out into a new file..I want to copy it to the clipboard and then use a hotkey to launch an application or powershell script that sends that copied text to a new instance of ...

Unable to run .exe installer from ASP.NET page

I'm attempting to create an ASP.NET/C# page that runs a PowerShell script that will run an .exe installer. The ASP.NET page is currently running in IIS 6.0 on Windows Server 2003. The PowerShell script works correctly from the PS command line but when invoked from the ASP.NET page the page just hangs. No processes are created and it ap...

How to get Powershell-ISE to release Cmdlet DLL

I'm development a Cmdlet and using Powershell-ISE to test. ISE is keeping my DLL locked and preventing from rebuilding and then reloading. I've tried call remove ps-snappin, but the DLL remains locked. ...

Add-Type -ReferencedAssemblies fails with could not load or find assembly. Solution

The solution to this problem is add the DLLs to the GAC as was suggested in one of the responses to my posting. As I noted in one of my responses, the gacutility will not be available in the environment where this process needs to run. Because of this the simple solution of the gacutility is not an option. To resolve this I derived a Pos...

powershell error checking during file copy with recursion

I have a program that copies folders and files recursively. example: Copy-Item -path "$folderA" -destination "$folderB" -recurse Sometimes the files do not copy. Is there a way to "step inside the recursion" or a better way to do it, so I can enable some kind of error checking during the process rather than after wards. Possibly even...

Kicking off a Performance Monitor Data Collector Set via PowerShell?

I have a need to kick off a Data Collector Set that I've predefined. I'm going to be writing a PowerShell script that monitors a condition on the system and when it detects that condition, it begins the Data Collector Set. How can I start this Data Collector Set? ...

using SmartFTP api with powershell - how do i exclude | include files?

I have a powershell script using smartftp api created via: $queueList = $smartFTP.CreateObject("sfTransferQueue.TransferQueueItem"); anyone know what I have to pass to queueList to send only .aspx pages or exclude them? is this what favorites manager is used for? $favMgr = $smartFTP.FavoritesManager; $rootFolder = $favMgr.RootFolde...

How can I control a window's 'state' (maximize, minimize, restore) with a powershell script?

I need to be able to run this script and have it maximize a window if it isn't already maximized. And restore the window if it isn't. The window is just whatever is currently active so no need to get specific (but bonus points if you do) 8O) I plan on activating it from a short-cut keystroke. It does need to run under PS v1 (I know, ...

Using Windows PowerShell as a batch scheduler

We have a series of nightly batch jobs running as Windows Scheduled Tasks. Their numbers have grown to a point that they are beginning to step on each other since there are no dependencies between the batch files, just start times. We are considering the use of PowerShell to write scripts to control the nightly cycle...can anyone confir...

search a string for an array of string fragments

Hi, I need to search through a string to see if it contains any of the text in an array of strings. For example excludeList="warning","a common unimportant thing", "something else" searchString=here is a string telling us about a common unimportant thing. otherString=something common but unrelated In this example, we would find the...

PowerShell get running explorer process and their documents

How can i access document property of already running explorer processes. i am using following line of code to get process. $ie2 = Get-Process |where {$.mainWindowTItle -eq "Windowtitletext"} | where {$.ID -ne $ieParentProcessNumber} now i want to do some processing on this processes like $ie2.Document etc. ...

Passing ComObjects in Powershell

Hi! I am trying to call some COM method which uses another COM object as argument via Powershell but I can't get it to work. $dbc = New-Object -ComObject "BMS.MOL.DBConnector" $client = New-Object -ComObject "BMS.MOL.Client" Calling $dbc.GetClient(1, $client) results in an unknown error (translated): Exception during call of "Get...

How can I output Handbrake output to both the screen and to a file?

So I've been using Handbrake command line to encode my video collection to store on my NAS so I can use it on my HTPC. I was looking for a way to output both to the screen so I can watch it's output as it's encoding, but also to a file so I can go back and look at a particular encoding session. My solution for this was to use one Powers...

Rename files to lowercase in Powershell

I am trying to rename a bunch of files recursively using Powershell 2.0. The directory structure looks like this: Leaflets + HTML - File1 - File2 ... + HTMLICONS + IMAGES - Image1 - Image2 - File1 - File2 ... + RTF - File1 - File2 ... + SGML - File1 - File2 ... I am using the following command: get-c...

Run a command using PowerShell on each directory with an assumed path component

I found this question, which is very similar to what I want but I just couldn't get it to work. I want to run process.exe on each subdirectory's XML directory of C:\ToProcess. If I did it by hand, the first 6 of the 50 or so commands would look like this: process.exe -switch1 -switch2 -i "C:\ToProcess\abx\XML" -o "C:\Processed\abx\XML"...

PowerShell FileInfo - Getting Custom Properties?

In the Windows Explorer I right click a DLL, choose Properties then the Version tab. In the 'Other Version Information' area, under 'Item Name' there is a custom field called 'SVNBuildVerion'. How can I retrieve that with PowerShell? I've tried : dir $targetDLL | select -ExpandProperty VersionInfo | fl * -force [System.Diagnostics.F...

How can I change the username and password of an application pool using the .NET ApplicationPool class?

I've read this article but it doesn't appear to use the ApplicationPool class described here. Feels like this is something simple I'm missing. Also, in case anyone feels like being extra helpful, I'm trying to accomplish this in a PowerShell script that can basically take a list of application pool names and set their credentials using...