powershell

conditional execution (&& and ||) in powershell

Hello! There's already question addressing my issue (http://stackoverflow.com/questions/563600/can-i-get-to-work-in-powershell), but with one difference. I need an OUTPUT from both commands. See, if I just run: (command1 -arg1 -arg2) -and (command2 -arg1) I won't see any output, but stderr messages. And, as expected, just typing: com...

Powershell: subtract $pwd from $file.Fullname

Scenario is: Given the following files c:\dev\deploy\file1.txt c:\dev\deploy\file2.txt c:\dev\deploy\file3.txt c:\dev\deploy\lib\do1.dll c:\dev\deploy\lib\do2.dll e.g. if $pwd is the following c:\dev\deploy running the statement $files = get-childitem I want to take this list and using << foreach ($file in $files) >> I want to subs...

Powershell v1 - deleteing all files & folders except in a named folder

I want to delete all the content and the children of a given root folder, however i want to keep some files (the logs), which all reside in a logs folder What is the elegant way of doing this in powershell. Currently i am doing it in multile steps, surely this can be done easily... i have a feeling my oo-ness/language bias is getting in ...

When creating App Pool and Virtual Dir Config

Hi, I'm using the app pool and virtual directory created here and I'm trying to figure out how to set the recycle worker processes in minutes for the app pool and for the virtual directory I'm trying to change the execute permissions to scripts and executables, adding the same username and password permissions for the virtual directory ...

How to run a PowerShell script from C# as non-elevated user

I'm trying to run a PowerShell script from a C# application and I need the script to run when my C# app is running as a non-admin user (e.g. Network Service or some other domain account). Previously, I was using the following code: using (RunspaceInvoke invoker = new RunspaceInvoke()) { // load the powershell module invoker.Inv...

Loading a Type Library via PowerShell and scripting Windows Live Writer

I'm very new to COM and Windows programming/scripting in general. What I was trying to do is scripting Windows Live Writer; according to the documentation before I can call $o = New-Object -c WindowsLiveWriter.Application I need to load the TLB first, so I should call the add-type command, unfortunately it fails: PS C:\Users\NoWher...

How to pass the parameter in SQL query from PowerShell

I have this code in PowerShell, that executes SQL query for UPDATE table: $Connection=new-object data.sqlclient.sqlconnection "server=server;database=mydb;trusted_connection=true;" $Connection.open() For( $i = 0; $i -le $ActID.Length; $i ++ ){ $cmd = New-Object System.Data.SqlClient.SqlCommand $cmd.Connection = $Connection $cmd.Comma...

Is it possible to invoke class methods, set/get properties from console or powershell

Hi, If I write a class library in Visual Studio, is it possible to write a console application or powershell script which can call the methods or set/get the properties? This is useful for testing APIs without having to create a form with loads of buttons etc. I actually meant my executing my own class libraries. So if I write a class...

Powershell - Dynamic Function Call

With custom Powershell functions all function output is returned. I'm attempting to remove that limitation/confusion by writing a wrapper function that will return just $true or $false. However, I'm struggling with the dynamic function call . . . specifically passing the arguments. Note that both the function name and the function...

Remove unwanted user permissions from SharePoint

I have a POSH script that sets a user's access to a specific folder for some files to read. The user's group gets assigned to the folder (which happens to be the same name). I then created a new view, set it to default, and told it to display all files without folders. This script has been working perfectly for 4 months but now some p...

Powershell scripting: recommended way to implement ShouldProcess when function calls are nested?

Test script: function outer { [cmdletbinding(supportsshouldprocess=$true)] param($s) process { $pscmdlet.shouldprocess("outer $s", "ShouldProcess") | out-null "" | out-file "outer $s" inner ImplicitPassthru inner VerbosePassthru -Verbose:$Verbose inner WhatifPassthru -Wh...

Writing powershell functions within a string

Hi. If I have: Write-Host "[$(Get-Date -displayhint time)] backup starting..." I get: [02/17/2010 1:26:12pm] backup starting... i. e. the Get-Date parameters are being ignored and is just returning the output of Get-Date. What's the best way to do inject the current time in the middle of a string? thanks ...

What (scripting) language to learn if I've already started with PowerShell ?

Some time ago I've started with PowerShell that is really great. I can code almost everyting I know, I can use .NET framework, WMI, even WIN API. Features like piping help me a lot to write manageable and readable code. V2 added advanced functions, modules, background jobs, remoting (woow) etc. As I said, I can do almost everything with...

How to POST to Vitalist.com's API via Powershell?

I'd liketo use Powershell to post a new action to my Vitalist.com account. The Vitalist API documentation is here. I've tried HttpWebResponse in Powershell but I'm missing something. Any pointers are appreciated. Thanks. ...

The number of messages on an MSMQ via Powershell

I'd like to provide a queuepath and get the number of messages thereupon. Any advice on how this could be done? ...

Support Get-Help for custom PowerShell cmdlet

I have created some custom PowerShell Cmdlets in C# and would like to provide some information to be displayed using the get-help cmdlet; e.g. "get-help my-cmdlet". I have created a basic snapin deriving from PSSnapIn and overridden the Description, Name and Vendor properties. I have also created my help file "Cmdlets.dll-Help.xml". C...

Powershell: filter string list

This seems like a very basic thing to do, but I am new to Powershell and can't figure this out or find an example online... I am trying to filter a list of strings. This list of strings is the result of a "svn list" command (subversion list of repository files), like: svn list -R PATHTOREPOSITORY I have tried svn list -R PATHTOREPOS...

osql in powershell 1.0?

I have an ODBC connection set up on my Windows 2008 Server, and I'm trying to replace some .BAT files that do some processing with Powershell files. Is there a way to do the same thing as this in PowerShell? CALL osql /instanceName /Uuser /Ppassword /Q"EXECUTE storedProcName @Parm1= %ePROFILE%, @param2 = N'%eValList%' ...

Permission issues across servers in powershell

I wish to have an automated process that basically deploys (copies) a asp.net web site in a CI situation. I have built the web site and I then want to copy the code to the web server. This powershell code is running on my build server. the build server is running under a defined service account and i have given that account full control ...

Powershell: Passing parameter of output script.

I am trying to call a script that gives data as a parameter for another script. ex. scriptA.ps1 -parameter1 (scriptB.ps1 -data 'testOne') I just put () because I thought that would work but can't seem to get it to work. Any ideas? I have tried $() and "" to no avail. Thanks. ...