powershell

How to output text without newline in Powershell?

I want my powershell script to print something like this: Enabling feature XYZ......Done The script looks something like this: Write-Output "Enabling feature XYZ......." Enable-SPFeature... Write-Output "Done" But Write-Output always prints a new-line at the end so my output isn't on one line. Is there a way do do this? ...

Rendering TabItem in WPF (with powerhsell)

Probably a simple question, but my brain isn't working today. I am writing a small powershell script to do various tasks. These tasks are logically grouped into tabs, using a WPF TabControl. A couple of the tabs do some checks to compare local file dates with server file dates, which takes a bit of time. (Only a few seconds, admittedly...

Run sysocmgr.exe on remote server using powershell remoting

Hi, I am unable to run remote installation of windows component on a remote server using sysocmgr.exe. It is working with "psexec.exe \ServerName -i sysocmgr.exe /i:%wnidir%\inf\sysoc.inf /u:\path\to\components.txt but I want to achieve the same results using powershell remoting. I have powershell remoting with WinRM working fine, but...

How to start a script at a specified point in Powershell

I have a powershell script I want to be able to define different starting points for. Once the starting point is hit the script would pick up from that point and continue through the remaining code in the script. I don't believe that a case statement will work since I don't think that will just let the script flow through from whateve...

How can you set focus to an inputbox with PowerShell?

I'm using the following PowerShell 2.0 code to grab input from a vb inputbox: [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') $name = [Microsoft.VisualBasic.Interaction]::InputBox("What is your name?", "Name", "bob") Sometimes when I run it the input box appears behind the active window. Is there a way...

SharePoint script fails when run as a Visual Studio post-deployment command

I have written a script that inserts some test data into a document library. I intend to use it as a post-deployment step in Visual Studio 2010, so that the library is not empty after a retract & deploy. The relevant portions of the script are: Install.ps1: $scriptDirectory = Split-Path -Path $script:MyInvocation.MyCommand.Path -Paren...

Running Pine/Alpine within a windows powershell

Hi, I am attempting to move most of my daily working life to a terminal shell. I am a .NET dev so I run on WinXP purely for visual studio (just wait until I get better at emacs). I would really much like it if I could use an email client within a terminal (either using Console or powershell within Console). From my uni days I know of ...

Why do I need to have my functions written first in my Powershell script?

I have a script that I am utilizing functions to wrap parts of the code that allow me to move through the sections at a specified point. What I have found is that I have to have the functions listed first in the script for it to run correctly. Example: $stepChoice = read-host 'Where would you like to start.' switch($stepChoice) { ...

Get current user's credentials object in Powershell without prompting

I have a Powershell script that is going to be run through an automation tool against multiple servers. It works fine on Windows machines, as the remote calls use the tool's service account without any need for prompting or exposing any credentials in code. This script also runs against Linux machines via SSH using the SharpSSH package. ...

How to check if a cmdlet exists in powershell at runtime via script

I have a Powershell script that needs to run under multiple hosts (PowerGUI, Powershell ISE, etc...) but am having an issue where sometimes a cmdlet doesn't exist under one of the hosts. Is there a way to check to see if a cmdlet exists so that I can wrap the code in an if block and do something else when it does not exist? I know I co...

Can I tell if an ado.net DbCommand is a query or not (before executing it)

I am trying to write a Powershell script to run a general SQL command against a database. The idea is that Run-SQL "select ..." will run the SQL text against the currently open database. If the SQL statement is a query, it should return a DataTable. If it is a non-query (DDL or DML) it should return nothing ($null). In order to do this,...

Delete files defined in an array with Powershell

Is it possible to define an array of filenames (all files in different folders) and then in a loop delete them all, or do something else? Actually I need to create a few symbolic links using mklink to one file, putting those links in a different folders, replacing the old links if there was any. ...

Make PowerShell think an object is not enumerable

I've been working on some PowerShell functions to manage objects implemented in an assembly we have created. One of the classes I have been working with implements IEnumerable. Unfortunatly, this causes PowerShell to unroll the object at every opportunity. (I can't change the fact that the class implements IEnumerable.) I've worked a...

Enumerate Form Controls

I have this C# code to enumerate controls of a Form instance: private void button1_Click(object sender, EventArgs e) { textBox1.Text = ""; Form2 form2 = new Form2(); foreach (Control control in form2.Controls) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(control); ...

Loading XML string with PowerShell

I have defined an XML string using $str = "<a><b></b></a>" Now I want to load it into a [xml] variable to be able to manipulate it's nodes etc. The row below results in an error... $str = [xml]"<a><b></b></a>" How do I do this? ...

Include code in string definition?

I have a string $string = "Active Directory" and I want to make another string Active_Directory_Results.txt I would like to just do $otherstring = "$string.Replace(" ","_")_Results.txt" but that doesn't work out. What would be the correct way to pull this off? ...

Showing WinForms dialog with focus from powershell script.

One of my coworkers just came to me with an interesting problem. He's displaying a WinForms form from a PowerShell script, and while the form opens successfully it does not get focus. Instead the PowerShell command window retains focus until the form is explicitly clicked. The script is being run from the PowerShell command line using ...

PowerShell: How to check for multiple conditions (folder existence)

I am in the process of writing a script to make changes to folder permissions. Before it does that I would to do some checking to make sure that I am working in the correct directory. My problem is how do I check to see if four subfolders (i.e. Admin, Workspace, Com, & Data) exists before the script progresses. I assume I would be using ...

Powershell Start-Job won't run

I'm trying to run a simple job process in powershell 2.0 and it doesn't seem to run. $job = Start-Job { Return "Some string." } When I call $job, the status says it's running. But the problem is that it never completes. Tried the same thing on my Windows 7 machine and it completes immediately. I'm running powershell 2.0 on wind...

Function overloading in powershell

Can you overload functions in powershell ? What I want to do is that my functin could accept string, array or some switch. Example what I want: Backup-UsersData singleUser Backup-UsersData @('Alice', 'Bob', 'Joe') Backup-UsersData -all Best regards. ...