powershell

Using Powershell's bitwise operators

I'm looking for example of how I would solve the scenario below: Imagine my printer has the following property for "Status" 0 -Offline 2 -Paper Tray Empty 4 -Toner Exhausted 8 -Paper Jam When I query status it returns a value of 12. I can obviously see that this means the printer has the Toner Exhausted and a Paper Jam, but how would...

Set-SPDebug -trace 1 not working in PowerShell host

I have a few PowerShell hosts, and in these hosts Set-SPDebug -trace 1 does not work. I tested PoshConsole, here it works, but for example the Host6 in the PowerShell SDK does not work. Any idea what is required in a host to get this working? ...

how to send an email with attachement using powershell v1?

how to send an email with attachement using powershell v1? ...

ASP.NET PowerShell Impersonation

I have developed an ASP.NET MVC Web Application to execute PowerShell scripts. I am using the VS web server and can execute scripts fine. However, a requirement is that users are able to execute scripts against AD to perform actions that their own user accounts are not allowed to do. Therefore I am using impersonation to switch the id...

How to run PowerShell scripts via automation without running into Host issues

I'm looking to run some powershell scripts via automation. Something like: IList errors; Collection<PSObject> res = null; using (RunspaceInvoke rsi = new RunspaceInvoke()) { try { res = rsi.Invoke(commandline, null, out errors); } catch (Exception ex) { LastErrorMessage = ex.ToString(); Debug....

How can I get PowerShell Added-Types to use Added Types

I'm working on a PoSh project that generates CSharp code, and then Add-Types it into memory. The new types use existing types in an on disk DLL, which is loaded via Add-Type. All is well and good untill I actualy try to invoke methods on the new types. Here's an example of what I'm doing: $PWD = "." rm -Force $PWD\TestClassOne* $code...

UI-Automation cmdlet not finding the control

Hi, I am trying to test a WPF application using the UI-Automation framework that MSFT provides. There were a few powershell scripts written that invoked the cmdlets created to manipulate the visual controls of the application. There is a DropDown within my application that has an entry 'DropDownEntry'. In my cmdlet, I am trying to do s...

Join two results in Powershell

I've got two CMDlets that return lists of objects. One returns objects of the type SPSolution, which contains the property Id, the other returns objects of the type SPFeature with a property SolutionId. Now I want to join/merge this data something like this: $f = Get-Feature $s = Get-Solution $result = <JOIN> $f $s <ON> $f.So...

Avoid line breaks when using out-file

Hi everyone, I'm getting a little frustrated on a little PowerShell script I'm writing. Basically I loop through text files to check every line against an array of regular expression patterns. The result gets piped to the out-file cmdlet which appends it to another text file. Get-ChildItem $logdir -Recurse -Include @('*.txt') | Get-Co...

Replacement for Azure SDK Powershell commandlets for deployments

Hi, We've run into an issue with the New-Deployment Azure Powershell commandlet timing out; we've put in a bug report with MS. While they gave us an explanation for it (the path and timeout threshold used to upload through commandlets is different then what's used by the web portal); they don't have a fix for us. We need to get this ru...

On Windows XP - how do I use PowerShell background jobs which require windows authentication

I'm trying to run some funtions in the background of a PoSh script. The job never completes, but works fine when called normall. I've narrowed the problem down to the following line: This line works fine: $ws = New-WebServiceProxy "http://host/Service?wsdl" -UseDefaultCredential but this line blocks forever start-job { New-WebServi...

What is a proper way to pass a parameter to Set-Alias in powershell?

Hello. A little background: I use PowerShell on windows xp at work and I set a bunch of useful shortcuts in Microsoft.PowerShell_profile.ps1 in My Documents, trying to emulate Mac environment inspired by Ryan Bates's shortcuts I have things like: Set-Alias rsc Rails-Console function Rails-Console {Invoke-Expression "ruby script/conso...

Get-WMIObject fails when run AsJob

It's a simple question, but it's stumped me. $cred = Get-Credential $jobs = @() $jobs += Get-WmiObject ` -Authentication 6 ` -ComputerName 'serverName' ` -Query 'Select * From IISWebServerSetting' ` -Namespace 'root/microsoftiisv2' ` -EnableAllPrivileges ` -Credential $cred ` -Impersonation 4 ` -AsJob $joblist = Wait-Job -Job $jobs -T...

Powershell, find files only in subdirectories named OLD with a certain age

How can I get a nice list of files in a directory tree that contains multiple OLD Files, I d'like to see only files from directories named OLD that have a certain age. ...

How to use add-nlbclusternode in PowerShell

Hi, I'm newbie for PowerShell and NLB. PowerShell 2.0 has supported nlb in cmdlet and I can't add a remote machine to the cluster. Does Add-Nlbclusternode support to add a remote machine? If so, which param indicates the remote machine and interface, -HostName and -InterfaceName? like add-nlbclusternode -interfacename "xxx" -hostna...

How to pass a variable as an argument to a command with quotes in powershell

Hi there, My powershell script takes the following parameter: Param($BackedUpFilePath) The value that is getting passed into my script is: "\123.123.123.123\Backups\Website.7z" I have another variable which is the location I want to extract the file: $WebsiteDeploymentFolder = "C:\example" I am trying to extract the archive with t...

Muliple Foreground Colors in Powershell in One Command.

I want to output many different foreground colors with one statement. PS C:\> Write-Host "Red" -ForegroundColor Red Red This output is red. PS C:\> Write-Host "Blue" -ForegroundColor Blue Blue This output is blue. PS C:\> Write-Host "Red", "Blue" -ForegroundColor Red, Blue Red Blue This output is magenta, but I want the color to...

Powershell 2 copy-item which creates a folder if doesn't exist

$from = "\\something\1 XLS\2010_04_22\*" $to = "c:\out\1 XLS\2010_04_22\" copy-item $from $to -Recurse This works if c:\out\1 XLS\2010_04_22\ does exist . Is it possible with a single command to create "c:\out\1 XLS\2010_04_22\" if it doesn't exist. ...

PowerShell and interactive external programs

Hi all I'm attempting to write a PowerShell script that, among other things, runs two external programs, harvesting the output of one and providing it to the other. The problem is that the second program is interactive and asks for: - a password - an option (1, 2, or 3) - an option (Y or N) - output of external program 1 Note also th...

Get-ChildItem to Move-Item - path not found

I try to move my old logfiles to a yyyy\MM\dd folder structure by Get-ChildItem . -Recurse -Include *.log | Move-Item -Dest {"D:\Archive\{0:yyyy\\MM\\dd}\{1}" -f $_.LastWriteTime, $_.Name} -Force but i get a path-not-found error. update The source path does not seem to be the problem. It looks like using -Force on Move-Item does no...