powershell

what object-based shells are there?

I am planning to write an object-oriented shell (based on Python). I have many ideas already. But before I am going to implement it, I want to inspire me by some existing shell. What I basically mean by object-oriented: Parameters are not just an array of strings but an array of objects. The return value is also an object. There is no...

How to Prevent "svn diff" from Generating Unicode Output on Windows

On my Windows box, I tried to create a Subversion patch by using the command svn diff > my_patch.diff. The resulting file was encoded with UTF-16, rather than UTF-8 or ASCII, so when I tried to use patch (from GnuWin32) to apply the patch, it didn't work. I was able to convert the patch file to UTF8 by opening it in Notepad and saving ...

Format-List: sort properties by name

Is it possible to sort the output of the Format-List cmdlet by property name? Suppose that I have an object $x with two properties "A" and "B", and when I run Format-List with it I get (PS) > $x | Format-List B : value b A : value a I would like to have (PS) > $x | Format-List A : value a B : value b NOTE: I should have specified ...

Setting Inheritance and Propagation flags with set-acl and powershell

I am trying to mimic the action of right-clicking on a folder, setting "modify" on a folder, and having the permissions apply to the specific folder and subfolders and files. I'm mostly there using Powershell, however the inheritance is only being set as "subfolders and files" instead of the whole "this folder, subfolders and files". I...

Exchange Management Powershell with .Net

I get this error with the following code: System.Management.Automation.CommandNotFoundException: The term new-storagegroup.... RunspaceConfiguration rsConfig = RunspaceConfiguration.Create(); PSSnapInException snapInException = null; PSSnapInInfo info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerSh...

Exchange Management Powershell with .Net Return Code

How can I get the return code from the following command: RunspaceConfiguration rsConfig = RunspaceConfiguration.Create(); PSSnapInException snapInException = null; PSSnapInInfo info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException); Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsCon...

How to continue powershell script after executable crash and block

Hi, I have this simple script: $files = dir .\configs | ? { !$_.PSIsContainer } foreach($file in $files) { try { .\MyApp.exe -ErrorAction Stop $file } catch { write-host "!!!!!!!!!!!!error!!!!!!!!!!!!!!" continue } } The problem is that when .\MyApp.exe -ErrorAction Stop $file ...

Passing enum values to a function in PowerShell

I have a function accepting an enum value as parameter. As an example, consider something like: (PS) > function IsItFriday([System.DayOfWeek] $dayOfWeek) { if($dayOfWeek -eq [System.DayOfWeek]::Friday) { "yes" } else { "no" } } Now, if I invoke it like this, everything is fine: (PS) > $m = [System.DayOfW...

Exchange Management Powershell - How can I get the value of the Name property here?

How can I get the return value of only the Name Variable? RunspaceConfiguration rsConfig = RunspaceConfiguration.Create(); PSSnapInException snapInException = null; PSSnapInInfo info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException); Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsCon...

Reading and running Powershell file from text

Right now, I'm trying to use a Powershell script to read through a textfile and execute all of the Powershell scripts mentioned in it, but I can't get any results. I've tried specifying it this way: Start-Job -ScriptBlock{powershell.exe -noexit $val} -name $jobnum and this way: Start-Job -ScriptBlock{$val} ($val is the value of the li...

Script for add route

Scenary SO Windows 7 I need to connect to remot host via cisco vpn. Sometimes the host destination network is the same of local network. Example (Partial output of ipconfig command): Ethernet adapter Cisco Vpn Adapter: IPv4 Address. . . . . . . . . . . : 192.168.100.12 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Wireless...

How to Remove Background Color (PowerShell)

I was playing around with PowerShell today and added a background color to all text ...now I want it gone! Anyone know how to do that, as a side note I was trying to change the color of the whole blank area that fills the application (formerly known as the background ...good job Microsoft) so if you know how to do that please do share. ...

Issue with permissions when creating and copy directories

I have created a PowerShell script for copying files to a directory, the script, first creates a folder , or forces a new folder event if it exists. Then copies a directory from another location. After copying, the files I then need to copy the correct web config depending on a value given by the user execturing the script. The issue I a...

Powershell XML parse not working on subnodes

I am tring to parse the following file: <?xml version="1.0" encoding="UTF-8" ?> <printDrivers> <printDriver id="XE8550"> <inf>x28550p.inf</inf> <driverPath>\drivers\XEROX\8550\8550_Driver</driverPath> <printerPaths> <printerPath>\\print-man\man-25</printerPath> </printerPaths> </printDriver> ...

Is scriptblock parameter evaluation different for compiled cmdlets and advanced functions?

In experimenting with scriptblocks, I was attempting to use a scriptblock parameter with an advanced function and noticed that it performs differently than when supplied to a compiled cmdlet. In reviewing this blog post from the PowerShell Team blog, it appears that the PowerShell engine should be evaluating the scriptblock if a scriptb...

Power shell for downloading folders through ftp

Hi guys, I have a web application that generates and uploads documents (word, pdf etc) on the server. Now I am writing a power shell script that will first transfer these files to an ftp folder. This part is done. The second script will run on my back up server every day and download all the folders/files from that ftp server to my back...

Error with using PowerShell and COM objects

Hi, I'm trying to work over PowerShell using the CERTENROLLLib and CERTCLIENTLib (COM objects). $com = new-object -ComObject 'CERTCLIENTLib' But i'm getting error: Cannot load COM type CERTCLIENTLib. I think it is an issue with the namespace, but i don't have any idea what to do? Can anybody help? Thanks in advance! ...

PowerShell Script Template

I'm working on creating a script template to jump start the creation of new powershell scripts. A quick list of some of the things I'm considering: params block usage function main function support for -verbose, -debug etc Does anyone have something like this already, that they could share? ...

PowerShell removing console message colors when using tee-object

Is there any way to stop PowerShell from removing console message colors when using tee-object? When I run without tee-object I get the nice error and verbose powershell message colors like this: powershell.exe -noprofile -file $project_root/test_main.ps1 However, when I'm using tee-object (b/c I want logging to console & file), th...

Poweshell installing/uninstalling windows services on a remote machine

I am using powershell 1.0 and I need to install a service on a remote machine and first uninstall it if it exists. This is my script I have that installs the service, however, I seem unable to uninstall the service. I have tried installutil however the service path is a network path which installutil, throws errors over. I'm a complete...