powershell

Performing permissions change ala chmod / attrib with Powershell

I would like to do the equivalent of chmod -w+r-x foo or attrib +R foo in Windows Powershell. Putzing around, I notice a fairly gnarly Set-Acl function that looks significantly fancier than what I need. How do I do attrib +R foo in Windows Powershell? ...

Windows 7 Action Center messages

I would like to know how to read, via vbscript, WMI, Powershell etc -the new Windows 7 Action center messages that the user normally gets informed of. I want to read all those messages on each machine and store then in a central database, then disable the messages from displaying to the user on the local machines. My questions are - 1....

PowerShell InitializeDefaultDrive

Hi, In my custom powershell provider I want the user to be able to skip the internal call to InitializeDefaultDrives. The InitializeDefaultDrives method is called when the provider starts. I guess this is when I use the Add-SnapIn cmdlet to load my provider. So it looks like i'm searching for a way to add dynamic parameters to to the A...

List all devices, partitions and volumes in Powershell

Hi! I have multiple volumes (as nearly everybody nowadays): on Windows they end up specified as C:, D: and so on. How do I list these all like on a Unix machine with "ls /mnt/" with Powershell? ...

Powershell analog to 'quote words'

What is the Powershell equivalent to Perl's qw() function? In v2 I can write my own with -split, but I'm assuming that there's an exiting method that I just can't find in the documentation. ...

powershell: expanding variables in file contents

I have a file template.txt which contains the following: Hello ${something} I would like to create a PowerShell script that reads the file and expands the variables in the template, i.e. $something = "World" $template = Get-Content template.txt # replace $something in template file with current value # of variable in script -> get He...

PowerShell custom provider RemoveItem

I'm implementing a custom PowerShell provider. I'm now working on the remove-item cmdlet implementation. The RemoveItem method has the following signature: protected override void RemoveItem(string path, bool recurse) When I type: Remove-Item .\Myobject -recurse the PowerShell infrastructure provides me with the value true in the rec...

Is there something odd with Powershell and forwards slashes?

As far as I know, a forward slash is not a reserved keyword in powershell But running the following in cmd pops up an about dialog "C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:about The same in powershell gives: 'C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe' /command:about You must provide a value expression o...

How to access an indexed property on a COM object from Powershell

I'm using Powershell to talk to the Windows 7 task scheduler service via COM through the Task Scheduler 2.0 interfaces (e.g. ITaskDefinition). I want to pull out a particular trigger from the Triggers collection on ITaskDefinition. It appears that the proper way to extract a particular trigger is through the Item property, which is an in...

How to perform IISRESET with Powershell Script

Does anyone know how to perform IISRESET with Powershell Script? I'm using powerguieditor with powershell 1.0 instlled on a windows 2008 box. ...

How to run exe in powershell with parameters with spaces and quotes

How do you run this command in powershell: C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe -verb:sync -source:dbfullsql="Data Source=mysource;Integrated Security=false;User ID=sa;Pwd=sapass!;Database=mydb;" -dest:dbfullsql="Data Source=.\mydestsource;Integrated Security=false;User ID=sa;Pwd=sapass!;Database=mydb;",computername=10...

Powershell, trying to output only the path and lastwritetime on directories

I am trying to write a script that will output any directory that has not changed in over 90 days. I want the script to ONLY show the entire path name and lastwritetime. The script that I wrote only shows the path name but not the lastwritetime. Below is the script. Get-ChildItem | Where {$_.mode -match "d"} | Get-Acl | Format-T...

VBScript, Batch or PowerShell Script?

I'm trying to run various commands using psexec.exe from Windows Sysinternals. What I need is a simple script to read the output of those commands. For example if everything went OK, then it returns a 0. If something went wrong, then it will spit out an error code. How can it be done? ...

Powershell status information

What is the prescribed method for display status or progress information to a user from a Powershell script? For example, "Connecting to database..." Normally I'd print to STDERR. Powershell has a Write-Progress cmdlet, but that's for a progress bar. ...

PowerShell: how to copy only selected files from source directory?

I'm a Powershell newbie, trying to get a simple script to run. I have a list of files that I want to copy from some src_dir to a dst_dir. I wrote a simple script (which is obviously wrong since it didnt do anything when I executed it). Could someone please help check to see what I'm doing wrong? # source and destionation directory $sr...

Using Powershell to recursively rename directories using a lookup file

I need to rename a lot of directories and their sub directories. I have a csv file which contains the old directory names and the required new name. 1,blah,old_name1,new_name2,wibble 2,foo,old_name2,new_name2,bar 3,john,old_name3,new_name3,paul 4,george,old_name4,new_name4,ringo Note that some of the directory names are old_name1-m...

Need help with INI file in Powershell

Here is the deal, I am going through an INI file with some code. The idea is to return all of the categories found in the INI file with a regex, and then set at an arraylist = to results. So here is the code: switch -regex -file $Path { "^\[(.+)\]$" { $arraylist.Add($matches[1]) } } However, th...

Make a Powershell function/task run in the background.

I have a function that lets me write the file-path of files to a text file, depending on your input. That sounds confusing, but I don't know of a better way to put it, so here's the function: Function writeAllPaths([string]$fromFolder,[string]$filter,[string]$printfile) { Get-ChildItem -Path $fromFolder -Recurse $filter | Select-Obj...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I'm trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I'm not getting all of the matches that I see when I do the same thing in C# using the Regex object. Can someone explain what I am doing wrong...

Is there a cmdlet in PowerShell 2 to handle ipsec changes?

I am using System.Management.Automation to build a program that serves as a firewall, essentially, and I was wondering if there is a specific cmdlet in PowerShell 2 to handle ipsec changes for a server? (i.e., that duplicates netsh ipsec functionality)? Or would I have to write one? :P I am hoping for a cleaner solution than calling a ...