powershell-4.0

Replace Words with a linebreak

半腔热情 提交于 2019-12-12 03:48:02
问题 This is my Textfile (temp.txt): (test1 AND id=42343) AND NOT (test2 AND id=12234) AND NOT (test3 AND id=12342) AND NOT (test4 AND id=13342) I have to replace all ")AND NOT(" so that the file after formatation look like this: test1 AND id=42343 test2 AND id=12234 test3 AND id=12342 test4 AND id=13342 I tried this Script/Command: (Get-Content C:\temp.txt) |ForEach-Object{$_ -replace "[) AND NOT (]","`n`r"}|Set-Content C:\temp.txt But now the textfile looks terrible: es 1 i =42343 es 2 i =12234

Group-Object is showing a hashtable when using calculated properties

萝らか妹 提交于 2019-12-12 03:32:19
问题 Background From list of predefined servernames, I'm searching in config files and trying to group for each server all the files where it's found. A filename can be mapped to an application. Problem The grouping part is giving me problems. It keeps returning a hashlist where I just want the filename returned. SSCCE note: grouping is on filename in the sscce but the gist of the problem is the same This example is showing the entire line where the match is found instead of just the match @("A

SSRS SetItemDataSource giving exception

落爺英雄遲暮 提交于 2019-12-12 01:52:37
问题 Hello all I am trying to set the datasource to the created report but I am getting an exception as mentioned This is the code I am using $Proxy = New-WebServiceProxy -Uri $ReportingServiceUrl -UseDefaultCredential $ReportName = "MyReport" $path="/" $allitems = $Proxy.ListChildren("/",$true) #Select the newest report with correct name $ThisReport = $allitems | where {($_.Name -eq $ReportName) } | Sort-Object ModifiedDate -Descending | Select -first 1 $datasource = $DataSourceName

Access UserControl elements/properties from main window in a WPF XAML PowerShell script

不羁的心 提交于 2019-12-11 20:14:58
问题 I wrote the following Test.ps1 PowerShell script to display a WPF GUI: function LoadXamlFile( $path ) { [System.Xml.XmlDocument]$xml = Get-Content -Path $path $xmlReader = New-Object -TypeName System.Xml.XmlNodeReader -ArgumentList $xml $xaml = [System.Windows.Markup.XamlReader]::Load( $xmlReader ) return $xaml } # Main Window $MainWindow = LoadXamlFile 'MainWindow.xaml' # Page 1 $Page1 = LoadXamlFile 'Page1.xaml' $MainWindow.Content = $Page1 $TextBox1 = $MainWindow.FindName('TextBox1') # The

Can't kill off an .exe file using Powershell V4.0

家住魔仙堡 提交于 2019-12-11 19:31:52
问题 Please see below. For whatever reason I can't kill off any on the .exe process running. Randomly I have seen this script work which is why I think there is something else going on. All that I see is the whole script has worked when testing but then I promote to prod it just fires of the email part. Email part is fine. Will this code guarantee a kill of the processes even if they are hung. $process = Get-Process -Name "IVR1","IVR2","IVR3" $IVR1path = "C:\IVR1" $IVR2path = "C:\IVR2" $IVR3path =

Configure custom metric of AWS CloudWatch Agent for Windows EC2 Instance [%CPU,%Memory,%DiskSpace]

烈酒焚心 提交于 2019-12-11 18:19:36
问题 I have written a PowerShell script to automate of download,install,configuration and start of AWS CloudWatch Agent on Windows EC2 Instance. Right now I have a task to fetch Metrics of CloudWatch Agent such as %CPU Usage, %Memory Usage & %Disk Space usage of Windows EC2 Instance that would need to define on config.json which we configure using amazon-cloudwatch-agent-config-wizard.exe wizard. Please help me to get %CPU usage, %Memory Usage and %Disk Space usage configure on cloudwatch custom

Classify file extension and applying logic

时光怂恿深爱的人放手 提交于 2019-12-11 17:37:44
问题 Need to execute logic depending on the file extension. Input: $FileName = "ABC.tar.gz.manifest" or "ABC.tar.gz" or "ABC.zip" $EXTZ = ".zip" $EXTGZ = "tar.gz" $EXT = $FileName -match "$EXTZ" $EXT if ($EXT = 'True') { Write-Host "$EXTZ" } elseif ($EXT = 'False') { Write-Host "$EXTGZ" } But the problem is some files are having the double extension. How we can solve this? If the extension is .zip need to print "ABC". If the file extension is .tar.gz or .tar.gz.manifest need to print "XYZ". 回答1:

How to loop over the result (system.Data.DataSet object) of SQL run from PowerShell

瘦欲@ 提交于 2019-12-11 17:37:04
问题 I am trying to run a SQL from Power Shell(which is on my windows 7 64 bit desktop) and the remote database host is MS SQL Server 2012. I am running SQL1 by calling function Get-ODBC-Data which will give me single column of type string. It can have unknown number of rows (up to 20). Then I am using each of these column values as parameter ($var1) to the second function Get-ODBC-Data-Count. The SQL2 in this function Get-ODBC-Data-Count will give me count using $var1 in where clause. The code is

How to sort a Multi Dimensional Array in Powershell

梦想的初衷 提交于 2019-12-11 12:37:03
问题 I have a script to cleanup a folder regularly. Every month there are 3-4 sub folders created; what i am trying to accomplish is keep a single folder per month and delete the rest on that folder on every server. I was successfull with the script, but ran into below block. My array looks as below; $Array = ((Filepath,Timestamp2),(Filepath,Timestamp3),(Filepath,Timestamp1),(Filepath,Timestamp4)) What i would like to do is, sort elements in array by timestamp; how to do that? Please let me know

Piping values to New-Item to create directories in PowerShell

独自空忆成欢 提交于 2019-12-11 12:23:24
问题 I've got a directory, C:\temp\test\ , containing three DLL's I've called First.dll, Second.dll, Third.dll. I want to create sub-directories named after each of the DLL's. This is what I've tried so far: $dirName = "Tenth" new-item $dirName -ItemType directory That works. It created a sub-directory called "Tenth". This also works: (get-childitem -file).BaseName | select $_ It returns: First Second Third I've checked the type of the output from that command and it tells me "select $_" is of