powershell

Test in PowerShell code if a folder is a junction point?

How can I test in PowerShell code if a folder is a junction point? ...

Script to pull out info out of very large drives

Hi Guys, I need a script that can gather folders/files information from large drives (600GB to 1TB). The info that I will need are: Full name/path of the file File Size Date Created Date Modified Date last accessed. So far I have the code below: dir 'e:\' -recurse | select FullName,Length,CreationTime,LastWriteTime,LastAcces...

How to Load Function in new Powershell.exe Console

I have a function (function1) which requires sta mode. I'd like tocall this function from a non sta mode poshconsole. This works when i have function1 in my Profile $command = "function1 'MyArguments'" powershell -sta -command $command But how can i do this when i have the function1 not in the profile and i call powershell -sta -no...

Automatically sign powershell script using Get-PfxCertificate

I have to sign remote scripts with a certificate from the remote machine from which I have a .pfx file. I would like to automate the scripting by supplying the password to the Get-PfxCertificate programmatically. So the question is: Is it possible to somehow supply programmatically the required password to Get-PfxCertificate? ...

Exchange 2007 Powershell SnapIns not registering under Windows 7/Visual Studio 2008SP1

I have a user management application that I've written that works great under XP but as part of our prep for moving up to Windows 7 I have been trying to get it to run under Windows 7 and my Exchange PSSnapIn is not playing nice. It always reports "No snap-ins have been registered for Windows PowerShell version 2." But I can go ru...

How to loop through files (full path) in PowerShell

How do I do the equivalent in PowerShell? Note that I require the full path to each file. # ksh for f in $(find /app/foo -type f -name "*.txt" -mtime +7); do mv ${f} ${f}.old done I played around with Get-ChildItem for a bit and I am sure the answer is there someplace. ...

Using powershell to edit multiple XML files

How can I get a list of multiple XML files from a specified directory and for each file add an element under the second root node using powershell? Example: I want to add <LastName>SomeName</LastName> within the FIRST <Names> element: <People> <Names> <FirstName>someFirstName</FirstName> </Names> <Names> <FirstName>my...

PowerShell scripts in BizTalk 2009 for pre-processing and post-processing in deployment?

My attempts to add a(ny) PowerShell script as a BizTalk 2009 PreProcessingScript oder PostProcessingScript (Application -> Resources -> Add) are always met with an error message Validation failed for 1 resource(s). Cannot add an unsupported script type (extension = ".PS1"). Verify the source location "c:\somescripts\BtsDumpEnvironmen...

Killing processes from list of executable names in PowerShell

I've got a PowerShell function that's returning a list of executable names (with the file extension), and I'm trying to kill any of these if they are running, but not having much success. Here's the command I'm using: Get-Executable-Names ` | where { $_ -match ".exe" } ` | foreach { $_ -replace ".exe" } ` | foreach { ps $_ } ` | kill ...

Connecting git to github on windows 7 without bash

I'm setting up git on my new Windows 7 machine and I'm hitting a roadblock when it comes to getting github to acknowledge my ssh key. I am doing things a little different from the standard script in that I would rather not use cygwin and prefer to use my powershell prompt. The following is what I did: I installed msysgit (portable). I...

Does anyone have a PowerShell script to batch encode files using Expression Encoder 3?

I have a set of WMV files that I need to convert to H.264. I have Expression Encoder 3 and can do each through the UI. Just trying to find a script to batch it through PowerShell using the Encoder 3 SDK. Thanks ...

Custom PowerShell Host and Converting PSObject back to base type

When hosting the PowerShell runtime is it possible to convert a PSObject back into its original type some how? For example: I have a cmdlet that calls WriteObject and pushes a collection of ClassXzy in the pipeline. When I call PowerShell.Invoke from the host end of things I retrieve a collection of PSObjects with a BaseObject propert...

PowerShell variable collisions.

I have a variable that is common to most of my app called "emails". I also want to use "emails" as the name of a parameter in one of the scripts. I need to refer to the value of both variables in the same script. Ideally there would be a way to refer using module/namespace or something and perhaps there is but I don't know it. You can se...

Is there a Language Reference Manual for PowerShell?

I'm evaluating Windows PowerShell as a replacement for cmd.exe for basic process automation for command-line code (e.g. setup, execution, and post-processing of large numbers of Fortran jobs.) I know enough perl and shell to achieve what I want but I'm trying to stay within the Windows toolchain rather than needing to train my coworkers ...

Replace path in Powershell string

Hi everyone, in my script I check some files and would like to replace a part of their full path with another string (unc path of the corresponding share). Example: $fullpath = "D:\mydir\myfile.txt" $path = "D:\mydir" $share = "\\myserver\myshare" write-host ($fullpath -replace $path, $share) The last line gives me an error since $p...

Powershell ftp upload error 530 not logged in

Hi All, I am struggling to get a PowerShell script to work. I am very new to PowerShell so could be missing something stupid. $sourceuri = "ftp://ftp.mysite.com/myfolder/myfile.xml" $username = "user" $password = "password" # Create a FTPWebRequest object to handle the connection to the ftp server $ftprequest = [System.Net.FtpWebRequ...

How can I use PowerShell's get-acl cmdlet when a filename contains brackets?

Suppose I have a file named "test[1].txt". Both of these commands produce no output: PS C:\Temp> dir test[1].txt PS C:\Temp> get-acl test[1].txt PS C:\Temp> The good news is that the dir command has a -LiteralPath switch that tells it not to interpret any characters as wildcards: PS C:\Temp> dir -LiteralPath test[1].txt Direc...

What is the syntax to subscribe to an object's static event in PowerShell?

Register-ObjectEvent looks for a object instance in the required parameter InputObject. What is the syntax for an object's static (Shared) event? UPDATE: Correct syntax for TimeChanged: $systemEvents = [Microsoft.Win32.SystemEvents] $timeChanged = Register-ObjectEvent -InputObject $systemEvents -EventName 'TimeChanged' -Action { Write-...

PowerShell: How to limit string to N characters?

substring complains when I try to limit a string to 10 characters which is not 10 or more characters in length. I know I can test the length but I would like to know if there is a single cmdlet which will do what I need. PS C:\> "12345".substring(0,5) 12345 PS C:\> "12345".substring(0,10) Exception calling "Substring" with "2" argument...

Powershell, paginating output from foreach

Seems like this should be simple, but powershell is winning another battle with me. Simply wanting to output the name of all the services running on a system, and their executable path, and pipe that into something I can use to search through it like Less. So far I have: $services = get-WmiObject -query 'select * from win32_service...