powershell

powershell, sendkey() and appactive() strangness

I have a logon powershell script. As part of the script, it launches an app, then waits 4 seconds to wait for the computer to catch up, then sends some keystrokes. $deviceID = "123xyz" invoke-item ("C:\myapp") ... $myshell = New-Object -com "Wscript.Shell" start-sleep -s 4 $myshell.AppActivate("myapp");$myshell.sendkeys("1");$myshell.se...

generate text sequence in powershell

I just had to produce a long xml sequence for some testing purpose, a lot of elements like <hour>2009.10.30.00</hour>. This made me drop into a linux shell and just run for day in $(seq -w 1 30) ; do for hour in $(seq -w 0 23) ; do echo "<hour>2009.10.$day.$hour</hour>" ; done ; done >out How would I do the same in powe...

Powershell - Exporting to CSV question

I'm trying to export just the numerical value for two performance counters to CSV. I've been able to get something built together but I still need some assistance. $counter1 = "\\ygex01wal\SMTP Server(_total)\Messages Received Total" $counter2 = "\\ygex01wal\SMTP Server(_total)\Messages Sent Total" $data1 = Get-Counter ...

Execute process conditionally in Windows PowerShell (e.g. the && and || operators in Bash)

I'm wondering if anybody knows of a way to conditionally execute a program depending on the exit success/failure of the previous program. Is there any way for me to execute a program2 immediately after program1 if program1 exits successfully without testing the LASTEXITCODE variable? I tried the -band and -and operators to no avail, th...

Invoke-Expression with exe in Program Files

I'm trying to run a Powershell command to call 7-Zip to zip up a folder using the following command: $command = $SevenZip + " a " + $targetDirForZip + $GetDateName + "_" + $dir.Name + ".7z " + $dir.FullName Invoke-Expression $command The variables being fed into $command are already set and $SevenZip is "c:\Program Files\7-Zip\7z.exe"...

Argument Exception with GetVersionInfo and powershell

I am trying to use powershell to get the file version of a file. If I right click the file and look at the version, it shows a value. Here is how I am trying to do it: $path = "MSDE2000A"; $info = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path); Here is the exception information it is throwing: Exception calling "GetVersi...

Strange behavior in PowerShell function returning DataSet/DataTable

This is driving me crazy. I have a library I source from multiple scripts, which contains the following function: function lib_open_dataset([string] $sql) { $ds = new-object "System.Data.DataSet" $da = new-object "System.Data.SqlClient.SqlDataAdapter" ($sql, $_conn_string) $record_count = $da.Fill($ds) return $ds } T...

Microsoft's Unity and PowerShell

In a C# solution, I have multiple class libraries for the domain model, services, and repositories. I configured Unity in web.config of the main website project so that it knows what concrete objects to map to the services and repositories. For quick testing, though, I'd like to use PowerShell to load the assemblies and manipulate classe...

PowerShell: Load WebAdministration in ps1 script on both IIS 7 and IIS 7.5

I have a PowerShell script that configures web site and web application settings in IIS. So I use the cmdlets in the WebAdministration snap in. But this script needs to run on Windows 2008, Windows 7 and Windows 2008 R2. And I need it to run with minimal fuss from the user. The problem is that Windows 7 and Windows 2008 R2 use IIS 7.5...

How can i remove signing from Powershell?

so with $filestosign = (dir -recurse-include *.ps1) Set-AuthenticodeSignature $filestosign $signingcert i can sign all my ps1 files in a folder. But is there a quick way to undo this again? ...

PowerShell: suppress Write-Progress output

I have a PowerShell script that calls a CmdLet which in turn reports its progress using Write-Progress, and I would like to hide the progress bar. In is it possible to suppress or redirect the output of the Write-Progress CmdLet? ...

Powershell Command in C#

I am trying to query the names all of the WMI classes within the root\CIMV2 namespace. Is there a way to use a powershell command to retrieve this information in C# ? ...

Dependency Injection with PowerShell

Is it possible to use Dependency Injection (DI) with Windows PowerShell? My intitial experiments suggest that it isn't. If I attempt to use Constructor Injection in a CmdLet it doesn't even register itself. In other words, this is not possible: [Cmdlet(VerbsDiagnostic.Test, "Ploeh")] public class PloehCmdlet : Cmdlet { public Ploeh...

PS: Get index in an array list

I have an array of strings. Not sure if there is simple way to get the index of an item first found in the array? # example array $array = "A", "B", "C" $item = "B" # the following line gets null, any way to get its index? $index = $array | where {$_ -eq $item} | ForEach-Object { $_.Index } I could do it in a loop. not sure if there i...

Iterating over outlook emails very slow

Hello, Using COM access via PowerShell, I want to retrieve certain properties from Outlook folder items. The folder is a shared Exchange folder that has been synchronized in offline mode and outlook is put offline (should be no server access). I use this query, where $pt is MAPIFolder $ol = new-object -comobject "Outlook.Application" $...

Powershell TimeStamp on file name

I have a path in a string "C:\temp\mybackup.zip" I would like instert a timestamp in that script eg "C:\temp\mybackup 2009-12-23.zip" It there an easy way to do this in PowerShell. ...

Insert progressbar into statusbar panel using powershell and windows forms

I am currently working on a project that requires me to put a progressbar in one of the panels of a statusbar. Does anyone have any experience with this, or can anyone provide any input or direction on how it is done. I have been searching for 2 days now for a solution with no luck. There is still not an abundance of powershell help o...

Using HttpClient with the RightScale API

I'm trying to use the WCF Rest Starter Kit with the RightScale's Login API which seems fairly simple to use. Edit - Here's a blog entry I wrote on using Powershell to consume the API. Edit - Created a generic .NET wrapper for the RightScale API - NRightAPI It's exactly as simple as it looks while using CURL. In order for me to obtain...

How do I use Powershell to detach a SQL Server database?

I am sure that this can be achieved by loading the SQL Server Management Objects assemblies but I am curious as to whether the 'Start Powershell' item in the context menu within SQL Server Management Studio 2008 will give me a headstart. ...

download url content

Hi, i am working in a script, where I am able to browse the web content or the 'url' but I am not able to copy the web content in it & download as a file. This is what I have made so far: $url = "http://sp-fin/sites/arindam-sites/_layouts/xlviewer.aspx?listguid={05DA1D91-F934-4419-8AEF-B297DB81A31D}&amp;itemid=4&amp;DefaultItemOpen=1" $...