powershell-2.0

Can't install nuget package because of “Failed to initialize the PowerShell host”

江枫思渺然 提交于 2019-11-27 06:08:58
All of a sudden, I am getting this error when upgrading Nuget packages. None of the fixes that I have come across work. I am using Visual Studio 2013. 'Newtonsoft.Json 6.0.3' already installed. Adding 'Newtonsoft.Json 6.0.3' to Tournaments.Notifications. Successfully added 'Newtonsoft.Json 6.0.3' to Tournaments.Notifications. Executing script file 'F:\My Webs\BasketballTournaments\MainBranch\packages\Newtonsoft.Json.6.0.3\tools\install.ps1'. Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize

Using C# to execute PowerShell script with command line args using V2 methods

心已入冬 提交于 2019-11-27 06:01:38
问题 I am writing an C# application which will need to execute Powershell scripts with command line arguments and retrieve the output (aka what I would expect to see in the output window of PowerShell ISE - including exception information) I have found numerous code examples of how to accomplish this task using PowerShell V1 objects. These examples create runspaces, pipelines, etc. (ex Execute PowerShell Script from C# with Commandline Arguments) I have seen a few scant references to a different

How do I get only directories using Get-ChildItem?

狂风中的少年 提交于 2019-11-27 06:01:14
I'm using PowerShell 2.0 and I want to pipe out all the subdirectories of a certain path. The following command outputs all files and directories, but I can't figure out how to filter out the files. Get-ChildItem c:\mypath -Recurse I've tried using $_.Attributes to get the attributes but then I don't know how to construct a literal instance of System.IO.FileAttributes to compare it to. In cmd.exe it would be dir /b /ad /s For PowerShell versions less than 3.0: The FileInfo object returned by Get-ChildItem has a "base" property, PSIsContainer . You want to select only those items. Get-ChildItem

Extract a substring using PowerShell

烈酒焚心 提交于 2019-11-27 05:35:02
问题 How can I extract a substring using PowerShell? I have this string ... "-----start-------Hello World------end-------" I have to extract ... Hello World What is the best way to do that? 回答1: The -match operator tests a regex, combine it with the magic variable $matches to get your result PS C:\> $x = "----start----Hello World----end----" PS C:\> $x -match "----start----(?<content>.*)----end----" True PS C:\> $matches['content'] Hello World Whenever in doubt about regex-y things, check out this

Unblock a file with PowerShell?

女生的网名这么多〃 提交于 2019-11-27 05:24:44
问题 I am trying to have PowerShell unblock a file in Win2K8 R2. Does anyone have a pointer as to the syntax? 回答1: If you are using PowerShell v3, you can use the Unblock-File cmdlet. The "blocking" part is simply an alternate data stream of the file, named "Zone.Identifier". You can display it in CMD by using input redirection (no other way to get to a stream in CMD, though): H:\Downloads> more < test.exe:Zone.Identifier [ZoneTransfer] ZoneId=3 You can find them using dir /r on Windows Vista and

Basic Powershell - batch convert Word Docx to PDF

社会主义新天地 提交于 2019-11-27 05:04:18
问题 I am trying to use PowerShell to do a batch conversion of Word Docx to PDF - using a script found on this site: http://blogs.technet.com/b/heyscriptingguy/archive/2013/03/24/weekend-scripter-convert-word-documents-to-pdf-files-with-powershell.aspx # Acquire a list of DOCX files in a folder $Files=GET-CHILDITEM "C:\docx2pdf\*.DOCX" $Word=NEW-OBJECT –COMOBJECT WORD.APPLICATION Foreach ($File in $Files) { # open a Word document, filename from the directory $Doc=$Word.Documents.Open($File

PowerShell - Decode System.Security.SecureString to readable password

混江龙づ霸主 提交于 2019-11-27 04:47:57
I want to decode the password from a System.Security.SecureString to a readable password. $password = convertto-securestring "TestPassword" -asplaintext -force $credentials = New-Object System.Net.NetworkCredential("TestUsername", $password, "TestDomain") This code part works fine, I can use the $credentials object. But later in my code I need the password in a readable format. Because a methode needs the password in readable string. So I must decode the password back. How it is possible to decode the password from the $credentials object? Update Not working: $password = convertto-securestring

Redirecting standard input\\output in Windows PowerShell

社会主义新天地 提交于 2019-11-27 04:11:43
What is the required syntax to redirect standard input/output on Windows PowerShell? On Unix, we use: $./program <input.txt >output.txt How do I execute the same task in PowerShell? You can't hook a file directly to stdin, but you can still access stdin. Get-Content input.txt | ./program > output.txt For output redirection you can use: command > filename Redirect command output to a file (overwrite) command >> filename APPEND into a file command 2> filename Redirect Errors Input redirection works in a different way. For example see this Cmdlet http://technet.microsoft.com/en-us/library

How do I get only directories using Get-ChildItem?

余生颓废 提交于 2019-11-27 03:59:05
问题 I'm using PowerShell 2.0 and I want to pipe out all the subdirectories of a certain path. The following command outputs all files and directories, but I can't figure out how to filter out the files. Get-ChildItem c:\mypath -Recurse I've tried using $_.Attributes to get the attributes but then I don't know how to construct a literal instance of System.IO.FileAttributes to compare it to. In cmd.exe it would be dir /b /ad /s 回答1: For PowerShell versions less than 3.0: The FileInfo object

Redirection of standard and error output appending to the same log file

耗尽温柔 提交于 2019-11-27 03:37:34
I need to collect the standard output and error log from several processes into one single log file. So every output must append to this log file. I want to call all the jobs with lines like this: $p=start-process myjob.bat -redirectstandardoutput $logfile -redirecterroroutput $logfile -wait Where do I have to put the information to append? Andy Arismendi In order to append to a file you'll need to use a slightly different approach. You can still redirect an individual process' standard error and standard output to a file, but in order to append it to a file you'll need to do one of these