powershell-3.0

Conditional replace in XML files

青春壹個敷衍的年華 提交于 2019-12-02 12:00:14
问题 I'm replacing a text in XML files recursively using PowerShell. The script is working fine in replacing. However the XML files also have file paths which should not be replaced. This is the script currently being used if ( $content -match ' web site | web-site ' ) { $content -replace ' web site ',' New Site ' -replace ' web-site ',' New Site ' | Out-File $file.FullName -Encoding utf8 For example if the XML file has <title>web site</title> <subtitle>web-site</subtitle> <path>c:/web site

Powershell - Get-ADComputer -properties memberof

*爱你&永不变心* 提交于 2019-12-02 11:28:10
I am trying to find if any servers in our enviroment have NOT been applied to a particular group. I have a list of groups that we use to patch our Windows Servers on partiular days / nights / manual etc..., i am trying to check if any server in our enviroment was incorrectly put on the domain and missed this step - does not have a Patching Group Member. so far i i have: $servers = get-adcomputer -Filter 'ObjectClass -eq "Computer"' -properties * foreach ($server in $servers) { if($server.OperatingSystem -match "Windows Server 2008" -or $server.operatingsystem match "Windows Server 2003" ) {

is get-childItem's new -file parameter fast like -filter or slow like -include?

*爱你&永不变心* 提交于 2019-12-02 09:51:18
EDIT Hoping here to clarify my convoluted and misleading question... based on my mistaken assumption that -file accepts inputs. Thanks for setting me straight and pointing out that it's just a switch parameter; the inputs in my example actually get passed to -path. Sounds like that may be the fastest purely powershell way to search for multiple file types, since -filter accepts only a single input and -include is slower. The get-childItem documentation says "Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having

TFSSecurity to change git branch permissions

旧巷老猫 提交于 2019-12-02 09:39:40
I am implementing the TFS Security commands to change a git master branch acess control permissions to DENY for contribute field. Below is the command I am using: /tfssecurity.exe /a+ GitRepositories repositories/[543473b8-6186-42b3-bdab-b22bc44cc8f8/] GenericContribute n:'"[Projectname]\TFSGroup'" DENY /collection:CollectionURL" I am using powershell 3.0 for this project and I get below error Error: The security namespace GitRepositories does not exist. Could someone help me with this? You missed a blank space in "Git Repositories" name space. Try following: tfssecurity.exe /a+ "Git

Export function

不羁的心 提交于 2019-12-02 09:26:01
I am trying to create a function in which a user has to give a filename that can not containt an empty string. Besides that, the string can not contain a dot. When I run this function, I keep looping when I enter "test" for example. Any idea as to why? function Export-Output { do { $exportInvoke = Read-Host "Do you want to export this output to a new .txt file? [Y/N]" } until ($exportInvoke -eq "Y" -or "N") if ($exportInvoke -eq "Y") { do { $script:newLog = Read-Host "Please enter a filename! (Exclude the extension)" if ($script:newLog.Length -lt 1 -or $script:newLog -match ".*") { Write-Host

Powershell Script to count .txt files only in a directory

我们两清 提交于 2019-12-02 09:07:15
My goal is to send email to some users to notify about the current count of the files inside some folder directories. I need to count files only with .txt extensions and exclude folders and files inside this. please see below illustration U:\TESTING\Main Folder U:\TESTING\Main Folder\Sub Folder 1 U:\TESTING\Main Folder\Sub Folder 2 output result should look somehting like this Main Folder row should be 1 only, but it also includes the sub folders 1 and 2 and the txt files inside those. Here's the part of the code that counts the total files $total = Get-ChildItem $path -Recurse -File -Include

PowerShell comparison operators

一笑奈何 提交于 2019-12-02 08:35:42
PowerShell has a unique set of comparison operators: -eq -gt -lt -ne etc. I vaguely remember using such operators in a different language, but can't recollect which one. Which other languages use such notations? what is reason for not using the standard operators (==, >,<, !=)? The Unix test command for instance uses similar operators. Perl has operators like that too, although without the leading hyphen. The reason for PowerShell to use mnemnics rather than symbols for the comparison operators is probably that some of the commonly used comparison symbols are already in use for other

Powershell running as a another user with elevated privileges

情到浓时终转凉″ 提交于 2019-12-02 07:04:59
问题 I have two scripts located in C:\setup: script.ps1 and script1.ps1. I want to be able to run the script1.ps1 from withing script.ps1 as another user and with elevated privileges but I cannot make it work. The new powershell window opens but closes immediately ... here is the script: $cspath = $MyInvocation.MyCommand.Path $sfolder = Split-Path $cspath $spath = Join-Path $sfolder "\Script1.ps1" $sa = "domain\user" $sap = "userpassword" $sasp = ConvertTo-SecureString -String $sap -AsPlainText

Adding a complete directory to an existing zip file with System.IO.Compression.FileSystem

元气小坏坏 提交于 2019-12-02 07:04:37
问题 The following example is retraceable on the internet and on this website as a sollution to compress files using the .NET Framework 4.5 It works, but when the archive already exists it will give an error, as it only seems to be able to zip a folder and create a new zip file: [Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" ) $src_folder = "D:\stuff" $destfile = "D:\stuff.zip" $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal $includebasedir =

Trying to download a zip file from a weblink with powershell

非 Y 不嫁゛ 提交于 2019-12-02 06:23:12
问题 Ok, I am trying to download a file off of a web link that we use with powershell. I am downloading a zip file where the begining of the name is always the same, but the the middle part will change based off of the version number of the zip. I have been able to get the file to download when I use the fully qualified web address and have the file name hard coded into the script. I have tried every version of using the wild cards to get all the most common version of the zip, but it errors out