powershell

Troubleshooting a NullReference exception in a service

I have a windows service that runs various system monitoring operations. However, when running SNMP related checks, I always get a NullReference exception. The code runs fine when run through the user interface (under my username and password), but always errors running as the service. I've tried running the service as different user ...

Creating batch jobs in PowerShell

Imagine a DOS style .cmd file which is used to launch interdependent windowed applications in the right order. Example: 1) Launch a server application by calling an exe with parameters. 2) Wait for the server to become initialized (or a fixed amount of time). 3) Launch client application by calling an exe with parameters. What is the...

iTunes warning message on quit due to scripting

Wrote the following in PowersHell as a quick iTunes demonstration: $iTunes = New-Object -ComObject iTunes.Application $LibrarySource = $iTunes.LibrarySource foreach ($PList in $LibrarySource.Playlists) { write-host $PList.name } This works well and pulls back a list of playlist names. However on trying to close iTunes a warning appe...

How do I create a custom type in PowerShell for my scripts to use?

I would like to be able to define and use a custom type in some of my PowerShell scripts. For example, let's pretend I had a need for an object that had the following structure: Contact { string First string Last string Phone } How would I go about creating this so that I could use it in function like the following: funct...

How do I access the non-IPM_SUBTREE Public Folder Tree with WMI?

I'm trying to verify when the OAB (Offline Address Book) root folder for a new OAB is created with powershell. Is there a WMI class that exposes this? I'm using powershell, but any examples or links will do. ...

Equivalent of *Nix 'which' command in Powershell?

Does anyone know how to ask powershell where something is? For instance "which notepad" and it returns the directory where the notepad.exe is run from according to the current paths. ...

How can I perform HTTP PUT uploads to a VMware ESX Server in PowerShell?

VMware ESX, ESXi, and VirtualCenter are supposed to be able to support HTTP PUT uploads since version 3.5. I know how to do downloads, that's easy. I've never done PUT before. Background information on the topic is here: http://communities.vmware.com/thread/117504 ...

Pre-Pending a file to all .cs file in directory and subdirectory using PowerShell

How can I pre pend (insert at beginning of file) a file to all files of a type in folder and sub-folders using Powershell? I need to add a standard header file to all .cs and was trying to use Powershell to do so, but while I was able to append it in a few lines of code I was stuck when trying to pre-pend it. ...

Is there a Powershell "string does not contain" cmdlet or syntax?

In Powershell I'm reading in a text file. I'm then doing a Foreach-Object over the text file and am only interested in the lines that do NOT contain strings that are in $arrayOfStringsNotInterestedIn Does anybody know the syntax for this? Get-Content $filename | Foreach-Object {$_} ...

Move Active Directory Group to Another OU using Powershell

How do I move an active directory group to another organizational unit using Powershell? ie. I would like to move the group "IT Department" from: (CN=IT Department, OU=Technology Department, OU=Departments,DC=Company,DC=ca) to: (CN=IT Department, OU=Temporarily Moved Groups, DC=Company,DC=ca) ...

Powershell: Setting Encoding for Get-Content Pipeline

I have a file saved as UCS-2 Little Endian I want to change the encoding so I ran the following code: cat tmp.log -encoding UTF8 > new.log The resulting file is still in UCS-2 Little Endian. Is this because the pipeline is always in that format? Is there an easy way to pipe this to a new file as UTF8? ...

Any good PowerShell MSBuild tasks?

Anyone know of any good MSBuild tasks that will execute a PowerShell script and pass it different parameters? I was able to find B# .NET Blog: Invoking PowerShell scripts from MSBuild, but I'm hoping for something that is a little more polished. If I can't find anything I will of course just go ahead and polish my own using that blog p...

How do I call an Sql Server stored procedure from Powershell?

I have a large csv file and I want to execute a stored procedure for each line. What's the best way to execute a stored procedure from Powershell? ...

Can anyone recommend a good modern alternative to bash?

Bash is getting a little long-in-the-tooth. Windows has PowerShell (formerly known as Monad), which is capable of dealing with richer objects than just lines of text. Is there any equivalent new powerful shell for Linux/Mac? It should be of similar expressiveness and functionality to Bash, but not afraid to tackle things in a differ...

How do I get a list of the active IP-addresses, MAC-addresses and NetBIOS names on the LAN?

How do I get a list of the active IP-addresses, MAC-addresses and NetBIOS names on the LAN? I'd like to get NetBIOS name, IP and MAC addresses for every host on the LAN, preferably not having to walk to every single PC and take note of the stuff myself. How to do that with Windows Script Host/PowerShell/whatever? ...

.NET Framework method to quickly build directories

Is there a quick way to join paths like the Join-Path function in Powershell? For example, I have two parts of a path "C:\foo" and a subdirectory "bar". Join-Path will join these and take care of the backslash delimiters. Is there a built-in method for this in .NET, or do I need to handle this myself? ...

Vim with Powershell

I'm using gvim on Windows. In my _vimrc I've added: set shell=powershell.exe set shellcmdflag=-c set shellpipe=> set shellredir=> function! Test() echo system("dir -name") endfunction command! -nargs=0 Test :call Test() If I execute this function (:Test) I see nonsense characters (non number/letter ASCII characters). If I use cm...

Recursing the file system with Powershell

Anyone happen to have a sample script for recursing a given directory in a filesystem with Powershell? Ultimately what I'm wanting to do is create a script that will generate NSIS file lists for me given a directory. Something very similar to what was done here with a BASH script. ...

How can I uninstall an application using PowerShell?

Is there a simple way to hook into the standard 'Add or Remove Programs' functionality using PowerShell to uninstall an existing application? Or to check if the application is installed? ...

Installing Powershell on 600 client computers - Recommended settings.

I want to install Powershell to 600 xp computers and use it as the main processing shell, for example replacing batch scripts, VB scripts some other little programs. The installation process is not a problem. Some issues I think I'm going to come across are 1) Changing permissions to allow powershell to run scripts 2) The speed of po...