powershell

Exclude directories in PowerShell

I want to exclude all directories from my search in PowerShell. Both FileInfo and DirectoryInfo contain Attributtes property that seems to be exactly what I want, but I wasn't able to find out how to filter based on it. Both ls | ? { $_.Attributes -ne 'Direcory' } ls | ? { $_.Attributes -notcontains 'Direcory' } didn't work. How can I...

How can I grep for a text pattern in a zipped text file?

Our daily feed file averages 2 GB in size. These files get archived to a single zip file at the end of each month and stored in a network share. From time to time, I have a need to search for certain records in those files. I do this by connecting by remote desktop to the shared server, unzip the files to a temp folder, run grep (or Powe...

Why is PowerShell (with Perl) removing double quotes in a simple print statement?

Hi, I am am a longtime Linux user but am new to Windows and PowerShell. I just installed Windows7 and Strawberry Perl 5 for the first time. I now want to do a simple command-line print with Windows PowerShell. It looks like Perl installed correctly: PS C:\Users\Me> perl -v This is perl, v5.10.0 built for MSWin32-x86-multi-thread Cop...

Powerscript manipulating IE on Windows Server 2008

I'm trying to run my Silverlight tests via a command line (eventually MSBuild) working from this example. It all works fine on my XP Box but on Build Machine (Windows Server 2008) the IE window opens, then a second window opens with the Silverlight page in it. That page then shows the "Download Silverlight" picture and link. If I copy t...

Send mail via gmail with PowerShell V2's Send-MailMessage

I'm trying to figure out how to use PowerShell V2's Send-MailMessage with gmail. Here's what I have so far. $ss = new-object Security.SecureString foreach ($ch in "password".ToCharArray()) { $ss.AppendChar($ch) } $cred = new-object Management.Automation.PSCredential "[email protected]", $ss Send-MailMessage -SmtpServer smtp.gmail.c...

oracle without installing the data provider

I am creating a script that retrieves data from a local oracle db. As of now I have the oracle data provider for .net installed. However, this is a big file and a long installation process. Is there a way to deploy a software that utilizes the System.Data.OracleClient without having to install the data provider? ...

How can I break up a string with multiple XML root elements in PowerShell?

Hi All, I am writing a PowerShell wrapper for an existing Perl script. The Perl script is fed a couple of parameters and goes off and configures all our HP iLO devices for us, and returns the results in an XML format. The problem is the result comes out as one big blob of multiple XML statements ie: $strResult = & "perl locfg.pl -s $il...

How do I persist Powershell provider drive information?

In my Powershell provider, which is a business-logic layer over an SQL database, the Powershell drives equate to database connection settings. This collection of connection settings is persisted to an encrypted XML file on the local computer. An administrator may add these PS drives on a computer, supplying SQL Server credentials, that...

Is PowerShell a bottleneck

I'm working on a .net application that needs interact with Exchange, specifically creating Exchange objects. Its a web based application, but will have a back end running as a service on the Exchange server. I'm trying to decide the best way to interact with Exchange. My initial thoughts was to use powershell, with some sort of service ...

Oneliner to count the number of tabs in each line of a file

I have a file that is tab delimited. I would like a powershell script that counts the number of tabs in each line. I came up with this: ${C:\tabfile.txt} |% {$_} | Select-String \t | Measure-Object | fl count it yields 3, Which is the number of lines in the file. any pointers to what I'm doing wrong? I would like it to print a sin...

Showing Silverlight App in Browser From batch file on Win2008

I am trying to open a web page with a Silverlight App from a batch file on a Windows Server 2008 box. If I put this in the batch file: start iexplore http://www.google.com The google page shows. If I put this in the batch file (where TestPage has a Silverlight Application): start iexplore http://www.mysite.com/Configure/TestPage.ht...

How can I programatically set the owner of a MSMQ queue?

I have a powershell script that creates some private queues for me. However, the queues default to being owned by whoever ran the install script. I'd prefer to have them owned by a group (i.e. - Administrators or some such). Anybody know how to do this? foreach($strQueue in $strQueues) { if (![System.Messaging.MessageQueue]::Exists...

How can I bulk rename files using PowerShell?

I'm trying to recursively rename a bunch of TFS folders using tf rename, PowerShell and a regular expression but I'm having some issues with PowerShell as I haven't spent much time with it. This is what I've put together so far to replace a leading 5 with 2.3.2 but it isn't working: dir | foreach { tf rename $_ { $_.Name -replace '^5',...

Interacting with Exchange 2007

At the moment I am using powershell hosted in an asp.net app to communicate with Exchange, and create Exchange objects. Does anyone know of any other means of interacting with Exchange? These methods need to allow the creation of items such as mailboxes and distribution lists, so Exchange Web Services is out. ...

What's a good way to consume a PowerShell Cmdlet in a NAnt build system?

We use NAnt extensively for our build system. Recently, I've written a couple PowerShell Cmdlets to perform a few database related things. At first, the intent of these Cmdlets was not to necessarily run within our build process. However, this has recently become a need and we would like to run a few of these Cmdlets from our NAnt based ...

Finding out Last logon time in Windows through Powershell

How do you find out the last log-in time for a windows machine(any user) through powershell? ...

Powershell - Searching and Comparing Arrays with Quest CMDlets

Trying to determine if there are any user folders on the network that don’t have an associated user account. All results return "Missing" when the majority should return "Found". Any ideas? $Dir = "\\ServerName\Share\" $FolderList = Get-ChildItem($Dir) | where {$_.psIsContainer -eq $true} $UserList = get-qaduser -sizelimit 0 | select Lo...

How to read CDATA in XML file with PowerShell?

I am having a difficult time reading an XML file with Cdata inside. in $xmlsource <list> <topic> <topicTitle>Test</topicTitle> <topicDetail><![CDATA[<br>randomHTMLhere</br>]]></topicDetail> </topic> </list> powershell [xml]$xml = get-content $xmlsource foreach ($topic in $xml.list) { $topic.topicTitle $top...

Looking for a pure PowerShell IRC client

I'm looking for a IRC client library/script written in PowerShell. The goal is to replace a Perl script that uses Net::IRC to communicate with a MindAlign channel. SmartIrc4net will do in a pinch, but I'd rather have a pure implementation for simplicities sake. Ideas? ...

What exactly is "exit" in Powershell?

You can exit Powershell by typing exit. So far so good. But what exactly is this? PS Home:\> gcm exit Get-Command : The term 'exit' is not recognized as the name of a cmdlet, function, script file, or operable program. Ch eck the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 ch...