powershell-1.0

Can't get basic Powershell script running inside Team City

走远了吗. 提交于 2019-11-29 03:43:22
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 PsTools ), since Team City is configured to run under said account. Then, I created a Test.ps1 file with the same content and ran a command just like Team City's: [Step 1/4] Starting: C:\Windows\system32\cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -Command - <C:\TeamCity\buildAgent\temp\buildTmp

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

时光怂恿深爱的人放手 提交于 2019-11-28 06:53:54
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. Shay Levy Pipe it to the Measure-Object cmdlet Import-Csv C:\Directory\file.csv | Measure-Object Ten98 Get-Content and Measure-Object are fine for small files, but both are super inefficient with memory. I had real problems with large files. When counting rows in a 1GB file using either method, Powershell gobbled up all available memory on the server (8GB), then started paging to disk. I

How to Remove ReadOnly Attribute on File Using PowerShell?

让人想犯罪 __ 提交于 2019-11-28 04:48:05
How can I remove the ReadOnly attribute on a file, using a PowerShell (version 1.0) script? You can use Set-ItemProperty : Set-ItemProperty file.txt -name IsReadOnly -value $false or shorter: sp file.txt IsReadOnly $false MagicAndi $file = Get-Item "C:\Temp\Test.txt" if ($file.attributes -band [system.IO.FileAttributes]::ReadOnly) { $file.attributes = $file.attributes -bxor [system.IO.FileAttributes]::ReadOnly } The above code snippet is taken from this article UPDATE Using Keith Hill's implementation from the comments (I have tested this, and it does work), this becomes: $file = Get-Item "C:

Can't get basic Powershell script running inside Team City

删除回忆录丶 提交于 2019-11-27 17:56:58
问题 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 PsTools), since Team City is configured to run under said account. Then, I created a Test.ps1 file with the same content and ran a command just like Team City's: [Step 1/4] Starting: C:\Windows\system32\cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1

Capturing Powershell output in C# after Pipeline.Invoke throws

柔情痞子 提交于 2019-11-27 14:45:20
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 display the script's output up to that point. I haven't had any luck since results appears to be null when an exception is thrown. Is there something I'm missing? Thanks! m_Runspace = RunspaceFactory.CreateRunspace(); m_Runspace.Open(); Pipeline pipe = m_Runspace.CreatePipeline(); pipe.Commands.AddScript(File.ReadAllText(ScriptFile)); pipe.Commands.Add(

PowerShell generic collections

人盡茶涼 提交于 2019-11-27 06:44:39
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 Value --- ----- FOO BAR This however does not: $bar = New-Object "System.Collections.Generic.SortedDictionary``2[System.String,System.String]" New-Object : Cannot find type [System.Collections.Generic.SortedDictionary`2[System.String,System.String]]: make sure t he assembly containing this type is loaded. At line:1 char:18 + $bar = New-Object <<<<

How to Remove ReadOnly Attribute on File Using PowerShell?

六眼飞鱼酱① 提交于 2019-11-27 05:23:28
问题 How can I remove the ReadOnly attribute on a file, using a PowerShell (version 1.0) script? 回答1: You can use Set-ItemProperty : Set-ItemProperty file.txt -name IsReadOnly -value $false or shorter: sp file.txt IsReadOnly $false 回答2: $file = Get-Item "C:\Temp\Test.txt" if ($file.attributes -band [system.IO.FileAttributes]::ReadOnly) { $file.attributes = $file.attributes -bxor [system.IO.FileAttributes]::ReadOnly } The above code snippet is taken from this article UPDATE Using Keith Hill's

How to perform keystroke inside powershell?

家住魔仙堡 提交于 2019-11-26 17:38:09
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 Adi Inbar If I understand correctly, you want PowerShell to send the ENTER keystroke to some interactive application? $wshell = New-Object -ComObject wscript.shell; $wshell.AppActivate('title of the application window') Sleep 1 $wshell.SendKeys('~') If that interactive application is a PowerShell script, just use whatever is in the title bar of the PowerShell window as the argument to AppActivate (by default, the path to

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

萝らか妹 提交于 2019-11-26 10:25:57
问题 This question already has answers here : What's the best way to determine the location of the current PowerShell script? (14 answers) Closed 5 years ago . 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 a bit of a pain in the neck when trying to promote from \"dev\" to \"test\" to \"production\"

How to perform keystroke inside powershell?

雨燕双飞 提交于 2019-11-26 06:06:44
问题 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 回答1: If I understand correctly, you want PowerShell to send the ENTER keystroke to some interactive application? $wshell = New-Object -ComObject wscript.shell; $wshell.AppActivate('title of the application window') Sleep 1 $wshell.SendKeys('~') If that interactive application is a PowerShell script, just use whatever is