powershell-2.0

Merge multiple XML files into one using PowerShell 2.0?

蹲街弑〆低调 提交于 2019-12-04 05:32:21
I have a directory of very large XML files with a structure as this: file1.xml: <root> <EmployeeInfo attr="one" /> <EmployeeInfo attr="two" /> <EmployeeInfo attr="three" /> </root> file2.xml: <root> <EmployeeInfo attr="four" /> <EmployeeInfo attr="five" /> <EmployeeInfo attr="six" /> </root> Now I am looking for a simple way to merge these files (*.xml) files into one output file: <root> <EmployeeInfo attr="one" /> <EmployeeInfo attr="two" /> <EmployeeInfo attr="three" /> <EmployeeInfo attr="four" /> <EmployeeInfo attr="five" /> <EmployeeInfo attr="six" /> </root> I was thinking about using

Compiling new type in PowerShell v2 - Cookie Aware WebClient

拟墨画扇 提交于 2019-12-04 05:09:11
I am trying to compile a " cookie aware " version of the WebClient class - but I can't seem to get over some of the hurdles of using the Add-Type cmdlet added in PowerShell v2. Here is the code I am trying to compile: PS C:\> $def = @" public class CookieAwareWebClient : System.Net.WebClient { private System.Net.CookieContainer m_container = new System.Net.CookieContainer(); protected override System.Net.WebRequest GetWebRequest(System.Uri address) { System.Net.WebRequest request = base.GetWebRequest(address); if (request is System.Net.HttpWebRequest) { (request as System.Net.HttpWebRequest)

Wrapping Powershell script and files together?

谁说胖子不能爱 提交于 2019-12-04 05:07:12
问题 I'm currently using PS2EXE to compile my powershell script into an executable, works very well indeed! My problem is that this script relies on other files/folders. So instead of having these out with the exe I want to also have these files 'wrapped' up into the exe along with the PS script. Running the exe will run the PS script then extract these files/folders and move them out of the exe... Is this even possible? Thanks for your help 回答1: A Powershell script that requires external files

Check-Out files from TFS 2010 with powershell

强颜欢笑 提交于 2019-12-04 05:03:14
I only want to check out a path with powershell and also check in this path one minute later at Team Foundation Server. How can i do this? I have installed the tfs power tools at my server. You don't need the power tools. Just use the tf.exe command line util that comes with Visual Studio with TFS Team Explorer. tf edit <file> /noprompt to check out and tf checkin <file> /comment:$comment /noprompt to check in. Look at the command line usage on tf.exe for more info tf /? and tf checkin /? . You will need to configure your PowerShell session with the Path to tf.exe. This is usually done by the

Powershell - Run a script located at a remote machine which inturn access files from a network share

社会主义新天地 提交于 2019-12-04 04:58:32
问题 I'm trying to execute a powershell script located at a remote machine using the below command and it works great invoke-command (powershell c:\install\install.ps1) -computername box1 -credential (get-credential) The above script in-turn copies files from a network share (using robocopy) - It fails complaining the location doesn't exist. Found out it was due to permission issue. It works when I explicitly mentioned in the script to use the following credentials for the share net use \share1

How to delete all the files in a folder except read-only files?

旧时模样 提交于 2019-12-04 04:20:26
问题 I would like to delete all the files and subfolders from a folder except read-only files. How to do it using powershell? 回答1: The only objects that can be read-only are files. When you use the Get-ChildItem cmdlet you are getting objects of type System.IO.FileInfo and System.IO.DirectoryInfo back. The FileInfos have a property named IsReadOnly . So you can do this one liner: dir -recurse -path C:\Somewhere | ? {-not $_.IsReadOnly -and -not $_.PsIsContainer} | Remove-Item -Force -WhatIf The

Variables imported from the module becomes $null, after the same module imported again

為{幸葍}努か 提交于 2019-12-04 03:15:35
问题 I have a simple module: varExp.psm1 $var1 = 20 Export-ModuleMember -Variable var1 And I import this module into PS session: PS> Import-Module .\varExp.psm1 then PS> $var1 20 But after I import it second time PS> Import-Module .\varExp.psm1 PS> $var1 PS> $var1 becomes null... Anybody knows what is going on here? (PS2.0) Edit: There are workarounds: Forcing reloading with Import-Module .\varExp.psm1 -Force , and testing if module was loaded before: if(-not (Get-Module varExp)) { Import-Module .

Powershell To Check Local Admin Credentials

一世执手 提交于 2019-12-04 03:11:09
I'm trying to run a script that requires Administrator input in order to process certain things. Rather than have the script run unsuccessfully I'm trying to trap the error and throw it back into the Credentials, but I can't find a command I can pass Local Admin Credentials with to a Trap. Does anyone have anything that might work? I've found MANY that will check domain credentials, but this is a LOCAL Admin account. To clarify, I am using: $Cred = Get-Credential I need to verify the output from that is correct and has Admin access to run stuff further down in the script. Working Solution

Add text to every line in text file using PowerShell

耗尽温柔 提交于 2019-12-04 02:50:34
问题 I'd like to add characters to the end of every line of text in a .txt document. #Define Variables $a = c:\foobar.txt $b = get-content $a #Define Functions function append-text { foreach-Object { add "*" } } #Process Code $b | append-text Something like that. Essentially, load a given text file, add a "*" the the end of every single line of text in that text file, save and close. 回答1: Soemthing like this should work: function append-text { process{ foreach-object {$_ + "*"} } } 回答2: No

How to attach a file to an email with PowerShell

廉价感情. 提交于 2019-12-04 02:50:25
问题 I have written a PowerShell script that will create an email, however I can't seem to attach a file. The file does exist and PowerShell can open it, Could anyone tell me what I'm doing wrong? $ol = New-Object -comObject Outlook.Application $message = $ol.CreateItem(0) $message.Recipients.Add("Deployment") $message.Subject = "Website deployment" $message.Body = "See attached file for the updates made to the website`r`n`r`nWarm Regards`r`nLuke" # Attach a file this doesn't work $file = "K: