Questions tagged [powershell-1.0]

For issues relating to Windows PowerShell, version 1.0.

Windows PowerShell is a new Windows command-line shell designed especially for system administrators. The Windows PowerShell includes an interactive prompt and a scripting environment that can be used independently or in combination.

138 questions
102
votes
7 answers

How to Remove ReadOnly Attribute on File Using PowerShell?

How can I remove the ReadOnly attribute on a file, using a PowerShell (version 1.0) script?
Tangiest
  • 43,737
  • 24
  • 82
  • 113
64
votes
7 answers

How can I find the source path of an executing script?

I want to be able to tell what path my executing script was run from. This will often not be $pwd. I need to call other scripts that are in a folder structure relative to my script and while I could hard code the paths, that's both distasteful and…
Kevin Buchan
  • 2,790
  • 3
  • 27
  • 34
60
votes
1 answer

Copy-Item copies directory as well as contents to UNC path

I'm trying to take the contents of a folder and copy it to another using PowerShell 1.0. Pretty simple stuff and it all works fine using Copy-Item $from $to -recurse if I am copying from a local folder to a local folder. However, if the $to variable…
RhysC
  • 1,644
  • 1
  • 15
  • 23
49
votes
5 answers

How to perform keystroke inside powershell?

I have ps1 script to grab some information from the vmware cluster environment. In some place of ps1 script requires the ENTER button keystroke. So, How to do that ? -Thanks
37
votes
3 answers

PowerShell generic collections

I have been pushing into the .NET framework in PowerShell, and I have hit something that I don't understand. This works fine: $foo = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]" $foo.Add("FOO", "BAR") $foo Key …
EBGreen
  • 36,735
  • 12
  • 65
  • 85
31
votes
6 answers

PowerShell: how to count number of rows in csv file?

How can I count the number of rows in a csv file using powershell? I tried something like Get-Content -length "C:\Directory\file.csv" or (Get-Content).length "C:\Directory\file.csv" but these result an error.
jrara
  • 16,239
  • 33
  • 89
  • 120
17
votes
4 answers

PowerShell script to move files and folders including subfolders from one location to another older than x days

I developed a PowerShell script, and it's working absolutely fine. The only challenge is the files in the subfolders are not getting moved to the destination. get-childitem -Path "\\servername\location" | where-object {$_.LastWriteTime -lt…
16
votes
4 answers

Write-Host => Export to a file

I have got a script with some commands such as Write-Host "Server1". How can I export it to a file? When I tried with script > export.txt it didn't work.
expirat001
  • 2,125
  • 4
  • 30
  • 40
13
votes
3 answers

Can't get basic Powershell script running inside Team City

Here's my configuration: On the build log, I only see the output of the first two lines, and then "Process exited with code 0" as the last output of this build step. I tried opening a terminal in the build server in the SYSTEM account (using…
dario_ramos
  • 7,118
  • 9
  • 61
  • 108
13
votes
4 answers

Why is Powershell ISE showing errors that Powershell console does not show?

I'm running exactly the same script.ps1 file in a Powershell ISE (manually loading the script and pressing F5) and in a Powershell console (executing the script file). They both work but ISE shows errors that the console does not. Why? The code…
Malartre
  • 1,511
  • 18
  • 28
12
votes
4 answers

Capturing Powershell output in C# after Pipeline.Invoke throws

I'm running a Powershell test script from a C# application. The script can fail due to a bad cmdlet which causes pipe.Invoke() to throw an exception. I'm able to capture all the information I need about the exception, but I'd like to be able to…
Nick A
  • 311
  • 1
  • 2
  • 8
10
votes
1 answer

Size of the sorted file is double than original file in powershell

I have a powershell script, that reads file content, sorts it and writes output to new file. Following is the script: get-content $inputFile | sort > $sortedFile The output in file is sorted properly, but the output file ($sortedFile) is double…
9
votes
4 answers

Powershell remoting with V1

Do you know of any good remoting solutions using powershell V1 (I know the V2 stuff is awesome, but my organization doesn't like using pre-release software). I don't need anything spectactular, just a way to kick off powershell script on another…
Mike Shepard
  • 17,466
  • 6
  • 51
  • 69
8
votes
4 answers

Get-ChildItem recurse as a parameter in PowerShell

I am looking to create a function that could toggle the ability to recurse in cmdlet Get-ChildItem. As a very basic example: ... param ( [string] $sourceDirectory = ".", [string] $fileTypeFilter = "*.log", [boolean] $recurse =…
Sean
  • 926
  • 6
  • 11
7
votes
4 answers

Using PowerShell with .NET 3.5 runtime/libraries

Is it possible to run PowerShell 1.0 (or 2.0 CTP) backed by the 3.5 runtime instead of 2.0? We're building a .NET 3.5 solution, and I'd still like to use PowerShell as our scripting engine for scheduled tasks, etc. I don't need LINQ syntax or…
1
2 3
9 10