powershell-2.0

Powershell: How to capture output from the host

本秂侑毒 提交于 2019-12-10 15:45:13
问题 I am using powershell to automate some tasks related to checking out/merging in TFS. When I call tf get * /recurse I get a bunch of data scrolling by about the files that are getting checked out. The last line generated by this command (assuming its success) is one telling the checkin number. I would like to parse this out so it can be used later on in my script. I know that I can do something like $getOutput = tf get * /recurse but then the output is suppressed entirely and I want the output

Executing msbuild task from powershell

為{幸葍}努か 提交于 2019-12-10 14:45:24
问题 I am following this blog: http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx it's linked in this question as answer: Web.Config transforms outside of Microsoft MSBuild? Every step works as described but I want to call the transformation from a powershell script. I want to do this command in powershell msbuild trans.proj /t:Demo I found some forums saying that I should use invoke-expression When I try I get this error Powershell: Invoke-Expression $msbuild

PowerShell write-output missing information - prints only 1st object

瘦欲@ 提交于 2019-12-10 14:43:33
问题 1.ps1 has 2 objects created and printed. But only one show up in the output. Both objects show up in the following cases: (1) write-output is done with Format-List (2) object1 has more than 4 properties (and so it gets vertically formatted automatically) Trying to understand the reasoning behind this behaviour. PS C:\> cat .\1.ps1 $object1 = New-Object PSObject $object1 | add-member NoteProperty -name pn1 -value pv1 $object1 | add-member NoteProperty -name pn2 -value pv2 $object1 | add-member

Import-PSSession fails in script, works in shell

喜欢而已 提交于 2019-12-10 14:22:52
问题 I'm new to Powershell scripting and I'm working on a user management Powershell script, but I have run into a strange error. The following code works when I run it from the shell, but not when it is run from a script: $UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionURI http://servername/Powershell/ -Authentication Kerberos -Credential $UserCredential -AllowRedirection Import-PSSession $Session When I run it in a script with a Param()

Get-SPWeb is unable to find the object with ID or URL

有些话、适合烂在心里 提交于 2019-12-10 14:09:46
问题 QUESTION: I can't seem to figure out why I am getting the error below, even though the SharePoint sites exist, along with the document libraries being called. Document library Lib1 has documents/folders, document library Lib2 is empty. Anyone know what has gone wrong? ERROR: Get-SPWeb : Cannot find an SPWeb object with Id or Url : Lib1 and site Url https://sharepoint.oshirowanen.com/sites/oshirodev. At C:\Users\Oshiro\Desktop\CopyDocs.ps1:31 char:23 + $web = Get-SPWeb <<<< -Site $site

How to handle import of file with UTF-8 encoding, codepage = 65001, into SQL server

女生的网名这么多〃 提交于 2019-12-10 13:25:58
问题 In Norway we have 3 highly annoying characters, æøå, that create all sorts of problems. Since sql server 2008, Microsoft decided to not support codepage 65001. I have found a manageable solution to the problem of importing a UTF-8 file into sql server with OPENROWSET(BULK) and keep the æøå tokens. I created a powershell script that uses StreamReader and StreamWriter to convert the file from UTF-8 to default encoding, ANSI. $filename = "C:\Test\UTF8_file.txt" $outfile = "C:\Test\ANSI_file.txt"

How do I parse a date in PowerShell?

浪尽此生 提交于 2019-12-10 13:12:17
问题 I write a script that removes backups older than five days. I check it by the name of the directory and not the actual date. How do parse the directory name to a date to compare them? Part of my script: ... foreach ($myDir in $myDirs) { $dirName=[datetime]::Parse($myDir.Name) $dirName= '{0:dd-MM-yyyy}' -f $dirName if ($dirName -le "$myDate") { remove-item $myPath\$dirName -recurse } } ... Maybe I do something wrong, because it still does not remove last month's directories. The whole script

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

两盒软妹~` 提交于 2019-12-10 13:05:49
问题 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 larger than input file ($inputFile). Note: There are no duplicate or extra line in output file. Any help or ideas regarding this will be helpful. 回答1: Most likely the input file is ascii encoding while the default output using redirection is unicode

How do I call Start-Job which depends on a function in the same powershell module as the function calling Start-Job?

二次信任 提交于 2019-12-10 12:54:16
问题 I'm writing some powershell to talk to the AWS API, in a single module. I have written one function, Get-CloudFormation , which returns the status of a CloudFormation. I've written another function, Delete-CloudFormation , which after firing off a delete-CF API request, tries to start a job which polls the status of the CloudFormation using my Get-CloudFormation . I call Export-ModuleMember on Get-CloudFormation (but not Delete-CloudFormation ; that's a private function). Get-CloudFormation

Get a user's email address from the username via PowerShell and WMI?

只愿长相守 提交于 2019-12-10 12:47:07
问题 I have a user's network login name. From PowerShell and WMI is it possible to get a valid email for that user? Note that the login name is different than the name in the email, so I can't just combine the login name with the email domain. 回答1: The simplest way is to useActive-Directory. As you are using PowerShell tag and not PowerShell V2.0 you can use ADSI. Clear-Host $dn = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://WM2008R2ENT:389/dc=dom,dc=fr","jpb@dom.fr","Pwd") # Look