powershell-2.0

Powershell Add-Type suppress creation of .pdb when compiling .dll (C#)

泪湿孤枕 提交于 2019-12-23 02:56:32
问题 I am creating a C# hello world DLL and compiling it with the built-in powershell Add-Type command. When doing so, it creates an unwanted .pdb debug file in the directory with the .dll. How do I suppress creation of this .pdb file when using Add-Type command. I know in Visual studio we can disable that via an option, but cannot seem to find a proper cmd line syntax. Here is the example powershell code. Run from console and it will create the DLL on C:\ along with the .pdb Clear-Host Add-Type

Read file into line delimited array

随声附和 提交于 2019-12-22 18:18:07
问题 I'm using the 32-bit version of PowerShell and running it via the PowerGUI Script Editor. Everything online seems to think that Get-Content returns the file as an array; however, $lines = Get-Content -Path $xmlFilename Write-Host $lines.GetType() outputs System.String I know how to do this using the builtin .Net types; is there a PoweShell v2.0 way of doing this? 回答1: Are you sure that $xmlFilename file have more than one line separed by `n or `r`n? if the file contain just a single line you

Why would a get-process -computername return a couldn't connect to remote machine error?

瘦欲@ 提交于 2019-12-22 13:57:11
问题 I can execute the following command on a specific machine and it can return a list of processes on several target computers but returns a "Couldn't connect to remote machine" error on one machine. get-process -ComputerName 192.168.1.101 None of the target machines have powershell installed. The machine I am executing the powershell script on has 2.0 installed. I have admin privileges on all machines. The target machines that are able to return a list of processes remotely are server 2003

PowerShellPack - TaskScheduler module - run task with no logged user

允我心安 提交于 2019-12-22 10:48:54
问题 I need to schedule a task via Powershell v2 on Windows Server 2008. I am using the TaskScheduler module from the MS PowershellPack. Scheduling a task is ok, but I need the task to run even nobody is logged on. I saw that this is possible in Powershell v3 on Win8 or Win2k12 (this QA). But that is not my case - I need to this in Powershell version 2. Is this possible with module I am using? Or is there some workaround? 回答1: http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357(v=vs

Get-Date formatting/culture

旧时模样 提交于 2019-12-22 08:37:09
问题 How do I specify what part of my input string is the date and month? If the input is 01/10/2017 , this can be read as 1st Oct 2017 and 10th Jan 2017 . Both are correct. I want to be explicit that 01 is date and 10 is month, so that irrespective of locale and time format I can get a consistent result. Sample code: get-date -Date '01/10/2017' The output is: Tuesday, January 10, 2017 12:00:00 AM The desired output is: Sunday, October 01, 2017 12:00:00 AM 回答1: I have a solution for you. It

Cannot process argument transformation

a 夏天 提交于 2019-12-22 06:53:56
问题 Inspired by this post, I created the script below DOSCommands.ps1 Function Invoke-DOSCommands { Param( [Parameter(Position=0,Mandatory=$true)] [String]$cmd, [String]$tmpname = $(([string](Get-Random -Minimum 10000 -Maximum 99999999)) + ".cmd"), [switch]$tmpdir = $true) if ($tmpdir) { $cmdpath = $(Join-Path -Path $env:TEMP -ChildPath $tmpname); } else { $cmdpath = ".\" + $tmpname } Write-Debug "tmpfile: " + $cmdpath Write-Debug "cmd: " + $cmd echo $cmd | Out-File -FilePath $cmdpath -Encoding

Using PowerShell with .NET 3.5 runtime/libraries

夙愿已清 提交于 2019-12-22 05:02:37
问题 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 anything, just the 3.5 libraries and runtime. FOLLOWUP: thank you for the reply about dynamically loading assemblies. But let me clarify my question: is there any way to run PowerShell so that the 3.5 libraries run by default? So that if I enter New

Out-File -append in Powershell does not produce a new line and breaks string into characters

孤者浪人 提交于 2019-12-22 04:06:27
问题 I'm trying to understand some weird behaviour with this cmdlet. If I use "Out-File -append Filename.txt" on a text file that I created and entered text into via the windows context menu, the string will append to the last line in that file as a series of space separated characters. So: "This is a test" | out-file -append textfile.txt Will produce: T h i s i s a t e s t This wont happen if out-file creates the file, or if the text file has no text in it prior to appending. Why does this happen

How to execute a powershell script available in remote machine?

妖精的绣舞 提交于 2019-12-22 01:37:30
问题 I was trying to execute a script in remote computer. I did " Enable-PSremoting " in the remote machine. I placed a script hello.ps1 in remote machine. [My client machine is Windows XP and remote computer is Windows 2003 ] Then from my client computer i was trying to execute the script. invoke-command -computer $MachineName -filepath "C:\hello.ps1" I got the following error. Invoke-Command : Cannot find path 'C:\hello.ps1' because it does not exist. I think it tries to find script from client

Referencing System.Management.Automation.dll in a correct, multi-OS friendly way

醉酒当歌 提交于 2019-12-21 20:37:37
问题 I am writing a piece of C# that will invoke PS scripts. As part of this I’m referencing System.Management.Automation.dll, the library that the PS guys expose that makes my life easier. I assume this is the right library to use (internet searching seems to confirm but if I’m wrong let me know). This library is installed as part of the PS install / Windows SDK. I’m finding two weird things about this library: I always have to reference it with a full path (even though it’s in the GAC?) The path