powershell

Run a shell command with arguments from powershell script

Hello, I need to extract and save a some tables from a remote SQL database using bcp. I would like to write a powershell script to invoke bcp for each table and save the data. So far I have this script that creates the necessary args for bcp. However I can not figure out how to pass the args to bcp. Every time I run the script it just sh...

Please help me with a Power shell Script which rearranges Paths.

Hi, I have both Sybase and MSFT SQL Servers installed. There is a time when Sybase interferes with MS SQL because they have they have some overlapping commands. So, I need two scripts: A) When runs, script A backs up the current path, grabs all paths that contain sybase or SYBASE or SyBASE (you get the point) in them and move them all...

PowerShell copy fails without warning

Howdy, am trying to copy a file from IE cache to somewhere else. This works on w7, but not Vista Ultimate. In short: copy-item $f -Destination "$targetDir" -force (I also tried $f.fullname) The full script: $targetDir = "C:\temp" $ieCache=(get-itemproperty "hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"...

How to implement a password change check in Powershell?

I've created a set of virtual machines (Windows Server) with a specific admin password; these VMs have been assigned to users, and may be in use. I want to know if the user changed the admin password, and do the check so the user doesn't notice. What are good solutions in powershell? ...

Serializing WPF DataTemplates and {Binding Expressions} (from PowerShell?)

Ok, here's the deal: I have code that works in C#, but when I call it from PowerShell, it fails. I can't quite figure it out, but it's something specific to PowerShell. Here's the relevant code calling the library (assuming you've added a reference ahead of time) from C#: public class Test { [STAThread] public static void Main() ...

My PowerShell functions do not appear to be registered

Hi there, I have a script saved in a ps1 file in which I define 2 functions as such: function Invoke-Sql([string]$query) { Invoke-Sqlcmd -ServerInstance $Server -Database $DB -User $User -Password $Password -Query $query } function Get-Queued { Invoke-Sql "Select * From Comment where AwaitsModeration = 1" } In the PowerShell con...

Powershell: Read value from xml files

I need some with help with PowerShell, please. It should be pretty easy: I have a list of subdirectories, with a xml file in each one. I want to open each xml file and print the value of one node. The node is always the same, as the xml files are actually project files (*.csproj) from Visual Studio. I already got the list of files: get...

Generate SQL script to insert XML from files, using Powershell

I have a bunch of (50+) XML files in a directory that I would like to insert into a SQL server 2008 table. How can I create a SQL script from the command prompt or Powershell that will let me insert the files into a simple table with the following schema: XMLDataFiles ( xmlFileName varchar(255) , content xml ) All I need is for som...

IEnumerable<CustomType> in PowerShell

I'm trying to use Enumerable.ToList() in PowerShell. Apparently, to do that, I have to explicitly convert the object to IEnumerable<CustomType>, but I am unable to do that. It seems I can't correctly write IEnumerable<CustomType> in PowerShell. Both IEnumerable<string> and CustomType itself work correctly (the custom type I'm trying to u...

PowerShell question

Hey I got the following ps for retrieving the site template from SharePoint,but I do not quite undersantd what does the second half of the script( | ? {$_.IsHidden -eq $false }) does? Can someone explain this to me please as I am fairly new to PS. Get-SPWebTemplate | ? {$_.IsHidden -eq $false } ...

Can I get Raid disk status by using PS?

I have a HP server with Raid 5. Port 0 and 1 are used for data & OS mirroring. The software come with the Raid 5 is Intel Matrix Storage Manager and there is manager console as windows based api to view all the ports, including their status. Now they are all in Normal status. I am not sure if the OS/Windows has some APIs or .Net classes...

how to suppress output in R

Hi, I would like to suppress output in R when I run my r script from the command prompt. I tried numerous options including "--slave" and "--vanilla". Those options lessens the amount of text outputted. I also tried to pipe the output to "NUL" but that didn't help. Thanks a lot, Derek ...

Extracting columns from text file using PowerShell

Hi, I have to extract columns from a text file explained in this post: http://stackoverflow.com/questions/2499746/extracting-columns-from-text-file-using-perl-similar-to-unix-cut but I have to do this also in a Windows Server 2008 which does not have Perl installed. How could I do this using PowerShell? Any ideas or resources? I'm Pow...

Can you load a ps1 file from within a ps1 file?

can I load a ps1 file from within a ps1 file. The end goal is to make a ps1 file that I put in my profile on all my computers and have a floating profile that I can put paths to pocket utilities in. I'll probably put this in a code repo, or some outside sharing mechanism. ...

Increase number of concurrent shells in PowerShell V2

I'd like to increase number of concurrent shells in PowerShell V2.I tried using the following command ,but I got no luck.The error I got is" Error: Invalid use of command line. Type "winrm -?" for help." Can someone shine some light? winrm set winrm/config/winrs @{MaxShellsPerUser="50"} ...

How to group files by date using PowerShell?

I have a folder with 2000+ files. I want to count the files by date. so with: Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 2010-03-15 12:54 AM 10364953 file1.txt -a--- 2010-03-15 1:07 AM 10650503 file2.txt -a--- 2010-03-16 1...

Excel Data List Validation in Powershell

Hi, I have a range named "STATE". I want to set data validation in range ("A1") to only take value within this range using Powershell. Below is what I have tried. Does not work. I dont know what to put as 4th and 5th parameters. The first 3 are Excel constants equivalent to xlValidateList, xlValidAlertStop and xlBetween respectively. ...

Building Web Application project using MSBuild from command line on 64-bit: missing targets file

Building a solution containing a web application project using MSBuild from powershell like this: msbuild "/p:OutDir=$build_dir\" $solution_file Works fine for me on 32-bit, but on a 64-bit machine I am running into this error: error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplication...

Switch -Regex in Powershell.

$source |% { switch -regex ($_){ '\<'+$primaryKey+'\>(.+)\</'+$primaryKey+'\>' { $primaryKeyValue = $matches[1]; continue; } } I want to use dynamic key value with switch-regex, is that possible? ...

PowerShell - Set Alias for Loaded Assembly

I use this code to load a .Net assembly to PowerShell: [System.Reflection.Assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") | out-null [System.Windows.Forms.MessageBox]::Show("Hello world") Can I set an alias for an assembly (for example 'System.Windows.Forms' = 'Forms') so that...