powershell-3.0

PowerShell ISE throws an error on git checkout

别等时光非礼了梦想. 提交于 2019-12-17 16:45:38
问题 In PowerShell, git checkout runs without any error message. In the ISE, while git checkout stills works, the ISE gives an error message. > git checkout master Your branch is ahead of 'origin/master' by 3 commits. (use "git push" to publish your local commits) git : Switched to branch 'master' At line:1 char:1 + git checkout master + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Switched to branch 'master':String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError This isn

PowerShell changes return object's type

霸气de小男生 提交于 2019-12-17 16:32:47
问题 I am using PowerShell v3 and the Windows PowerShell ISE. I have the following function that works fine: function Get-XmlNode([xml]$XmlDocument, [string]$NodePath, [string]$NamespaceURI = "", [string]$NodeSeparatorCharacter = '.') { # If a Namespace URI was not given, use the Xml document's default namespace. if ([string]::IsNullOrEmpty($NamespaceURI)) { $NamespaceURI = $XmlDocument.DocumentElement.NamespaceURI } # In order for SelectSingleNode() to actually work, we need to use the fully

Difference between PowerShell Console and PowerShell ISE

狂风中的少年 提交于 2019-12-17 16:30:31
问题 What are differences between PowerShell Console and PowerShell ISE. I am asking this question in context of Profiles in PowerShell. Because PowerShell Console and PowerShell ISE both have differnet profiles. 回答1: From Differences between the ISE and PowerShell console:- Limited support for interactive console apps, try cmd.exe, then try cmd.exe /k a) cmd.exe /c dir still works though, and more information is available here http://blogs.msdn.com/powershell/archive/2009/02/04/console

Powershell 3.0 Invoke-WebRequest HTTPS Fails on All Requests

若如初见. 提交于 2019-12-17 15:57:09
问题 I am trying to work with our Load Balancer via Powershell 3.0 and a REST API. However I am currently getting a failure no matter what I try if it is an https request, whether to our load balancer or to any other https site. I feel like I'm missing something obvious. Here is the code that fails with https try { #fails #$location='https://www.bing.com' #fails #$location='https://www.google.com' #fails #$location='https://www.facebook.com' #fails #$location='https://www.ebay.com' #works #

Using Invoke-Webrequest in PowerShell 3.0 spawns a Windows Security Warning

对着背影说爱祢 提交于 2019-12-17 12:15:38
问题 When using the following code in PowerShell 3.0 PS> $data = Invoke-Webrequest -Uri stackoverflow.com PS> $data.ParsedHtml.getElementsByTagName("div") I get this warning: Windows Security Warning - To allow this website to provide information personalized for you, will you allow it to put a small file (called a cookie) on your computer? I would really like to suppress this message or add code to handle cookies , so the code could be scheduled. I have tried trusting the site in IE allowing

Start-Job passing XML object to -ArgumentList working different in Powershell V2 & V3

我与影子孤独终老i 提交于 2019-12-14 03:52:44
问题 I'm testing a deployment script for my application on Windows Server 2012 with Powershell v3. The script runs fine on Win Server 2008 R2 and Win 7 with Powershell v2. The issue I'm running into now is that I can not access properties of XML variables passed via -ArgumentList. I've been able to reproduce the issue on Win 7 and Win Server 2012 with Powershell v3 in a simple script that doesn't have any of the SharePoint, IIS, misc that my main script does. Script (I think I borrowed this from a

Import/Export .csv file

北城以北 提交于 2019-12-14 03:44:34
问题 I have testDates.csv with 100 dates date 1/10/17 6/10/18 9/10/42 ... I made a script that makes sample passwords based off these dates: $file = Import-Csv -Path U:\Desktop\testDates.csv foreach ($line in $file) { $fullDate = $line.date $year = Get-Date $fullDate -Format "yy" $currentDate = Get-Date $fullDate -Format "MM-dd" # Determining season if ($currentDate -ge (Get-Date 01-01) -and $currentDate -lt (Get-Date 03-01)) { $season = "Winter" } elseif ($currentDate -ge (Get-Date 03-01) -and

not getting output from receive job

杀马特。学长 韩版系。学妹 提交于 2019-12-14 03:26:00
问题 The variable $var is blank when I run this script: function FOO { write-output "HEY" } $var = Start-Job -ScriptBlock { ${function:FOO} } | Wait-Job | Receive-Job $var How do I get output from receive-job? 回答1: Start-Job spawns a new PowerShell instance in the background and as such has no knowledge of your function FOO which is defined in your initial instance There is an additional parameter InitializationScript which is called upfront executing your script block in the new instance which

This keeps doubling my output file!! how can i fix this?

≯℡__Kan透↙ 提交于 2019-12-13 09:08:00
问题 It keeps looking at your source file, then adding those changes to your output, since the source file doesn't change, it keeps adding those to the output $data = @( @{ pattern = "LACTION 'SQL\(''logility_prod_scp_logility''," replacement = "LACTION 'SQL(''LOGILITY_PROD_SCP_LOGILITY''," inputFile = "C:\files\DW_FEI_input1.ctg" outputFile = "C:\files\DW_FEI_output1.ctg" }, @{ pattern = "LACTION 'SQL\(''dwfei''," replacement = "LACTION 'SQL(''DW_FEI''," inputFile = "C:\files\DW_FEI_output1.ctg"

if script runs true restart/run next part

Deadly 提交于 2019-12-13 08:59:19
问题 I'm trying to get the script to restart the computer when the script returns $true, I'm planning to run the script in SCCM or task scheduler. I was going to get the SCCM to restart the computer if it returns $true but don't know how to so now I'm trying to add a restart within the script itself but don't know how to add it correctly . function Test-PendingReboot { if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return