powershell

What is a Powershell cmdlet?

Approaching cmdlets in a conceptual way, How are they made? Are they compiled? Is it the equivalent of a batch file for Powershell? Is it a script or a binary? What is the structure used for storing these cmdlets? ...

Should a Windows developer know the command line?

The command line has eluded me for years. I started in 1999 so I was already spoiled by the GUI; using my good ol' mouse to point and click away. Ten years later and I have some basic command line statements under my belt: cd, dir, rm, ipconfig, etc. Outside of that not much else. Heck, even my keyboard shortcuts are fairly limited t...

looping through a csv

hey guys, just wondering if i could do this in powershell, or even a c#/vb.net command line program. I have data that looks like this: I have a Teams Table. It looks like this: | id | teamname | teamcity | so for example, C2 has the value "Atlanta Braves". I need to split this up into "Atlanta" and "Braves". Data is consistent....

How do I dynamically create functions that are accessible in a parent scope?

Here is an example: function ChildF() { #Creating new function dynamically $DynFEx = @" function DynF() { "Hello DynF" } "@ Invoke-Expression $DynFEx #Calling in ChildF scope Works DynF } ChildF #Calling in parent scope doesn't. It doesn't exist here DynF I was wondering whether you could define DynF in such a way...

How to Populate Sharepoint MOSS 2007 Reference Data?

Hi, I need to populate reference data in a number of custom lists across difference versions (DEV, TEST and LIVE) of the same MOSS 2007 installation. Can anyone point me towards a way of doing this? I am initially looking at using a script (PowerShell?) or tool to populate this data. Thanks, MagicAndi. ...

OpenRemoteBaseKey() credentials

I'm attempting to use powershell to access a remote registry like so: $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $server) $key = $reg.OpenSubkey($subkeyPath) Depending on some factors that I'm not yet able to determine I either get Exception calling "OpenSubKey" with "1" argument(s): "Requested registr...

PowerShell: Does Version 2 work seamlessly with Version 1 scripts?

What sort of problems (if any) will I run into with the existing scripts once I make the jump to PowerShell2? I'm need to automate some tasks on a Windows XP production box, and PowerShell fits the bill. However, I can't install version 2 until it becomes official so my only choice at the moment is to install version 1 and write PS1 sc...

How to extract the number in the string "Task(12345)" with Regular Expression and Powershell?

How to extract the number in the string "Task(12345)" with Regular Expression and Powershell? I tried the following, but no chance. $file = gc myfile.txt $matches = ([regex]"Task\(\d{1,5}\)").matches($file) # Get a list of numbers Could someone please help me to find the correct regular expression? Thanks, Martin ...

PowerShell - Convert Ticks to Time

Converting dates/times into ticks using the PowerShell Get-Date applet is simple. However, how do you do the opposite operation; converting the ticks back into a date and time? ...

Try/catch does not seem to have an effect

I am new to powershell, and I am trying to add error handling via try/catch statements, but they don't seem to actually be catching the error. This is powershell v2 CP3. $objComputer = $objResult.Properties; $strComputerName = $objComputer.name write-host "Checking machine: " $strComputerName try { $colItems = get-wmiobject -class ...

Remote WMI StdRegProv GetString Access Denied

I'm attempting to use WMI to access a registry remotely via powershell. I'm using the following code to do this: $regUserPass = ConvertTo-SecureString -string "secret" -AsPlainText -Force $credentials = new-object System.Management.Automation.PSCredential("username", $regUserPass) $wmiReg = Get-WmiObject -list -namespace root\default -c...

Where can I find a list of Powershell .NET Type Accelerators?

In PowerShell you can use [xml] to mean [System.Xml.XmlDocument]. Do you know where I can find a list of these type accelerators? Are these accelerators specific to PowerShell or .NET? ...

Can you use an objects property in a string in powershell?

Basically I have the following code: $DatabaseSettings = @(); $NewDatabaseSetting = "" | select DatabaseName, DataFile, LogFile, LiveBackupPath; $NewDatabaseSetting.DatabaseName = "LiveEmployees_PD"; $NewDatabaseSetting.DataFile = "LiveEmployees_PD_Data"; $NewDatabaseSetting.LogFile = "LiveEmployees_PD_Log"; $NewDatabaseSetting.LiveBack...

How to capture a Powershell CmdLet's verbose output when the CmdLet is programmatically Invoked from C#

BACKGROUND I am using Powershell 2.0 on Windows 7. I am writing a cmdlet in a Powershell module ("module" is new to Powershell 2.0). To test the cmdlet I am writing Unit tests in Visual Studio 2008 that programmatically invoke the cmdlet. REFERENCE This Article on MSDN called "How to Invoke a Cmdlet from Within a Cmdlet" shows how ...

Best way to store powershell snapin names to be used by c# app for later use.

I have a c# app which executes rules, depending on an input. Some of the rules need to execute a poweshell script. I would assume that some of the scripts, as perhaps writtem by a user, would need a snapin to be available before they can execute correctly. I know I can add the snap in by doing something like this. RunspaceConfiguration...

Counting objects from Where-Object

I am currently trying to write a little powershell script (I have no experience in Powershell scripting so was wanting to use this as a test) that loops through our svn repositories counting how many commits have been made with a comment of "Reviewed by; No-one" as this indicates an unreviewed commit. I currently have the following $r...

Powershell, kind of set intersection built-in?

For some game where one would need to find anagrams from a bunch of loose letters I ended up implementing a permutation algorithm to find all possible anagrams and filter those if needed for known letter positions (-match is great, by the way). But for longer words this proved very much error-prone, as skimming a large list of gibberish ...

How to create a zip archive with PowerShell?

Is it possible to create a zip archive using PowerShell? Thank you. ...

Get list of files recursively by bit rate in powershell

How can you list all files (recursively) within a directory where the file (audio) bit rate is greater than 32kbps using powershell? ...

How to pass the current powershell pipe-object "$_" as a command line arg?

I'm trying to set all svn:property's on a set of piped files: dir * -include *.cs | Select-String -simplematch -pattern "HeadURL$" | select filename | svn propset svn:keywords "HeadURL Id LastChangedBy LastChangedRevision" $_ I get following error: svn: Try 'svn help' for more info svn: Explicit target required ('HeadURL Id LastChang...