powershell

Delete multiple lines in a text file using Powershell

只愿长相守 提交于 2021-01-28 05:26:25
问题 I have a text file like below: [Option] DuplicateUncoveredDiff = 1 KeptPatternMaxCount = 7 [6107] CtrlFlag = 10 Version =1532 [6900] CtrlFlag = 10 Version =1532 ...and some more text here I am trying to find a way to delete multiple lines under a group. When I say group, I am referring to the strings inside [ ] brackets and whatever is under it. For example, this is Group 1: [Option] DuplicateUncoveredDiff = 1 KeptPatternMaxCount = 7 Group 2: [6107] CtrlFlag = 10 Version =1532 Is there a way

Powershell determine base64 string file extension

给你一囗甜甜゛ 提交于 2021-01-28 05:20:34
问题 I have an XML file that has file attachments encoded in Base64 within it (InfoPath). When I use Powershell to decode the Base64 string for the attachment, it seems like I have to write the file path and extension into the WriteAllBytes command but I don't know whether the original file was a PDF, image file, DOCX, etc. - is there a way to have it write the string into the original filename and/or extension and I just specify the folder where it needs to go? Example code: $b64str = $xml

What am I not getting about [DateTime]::ParseExact()?

爱⌒轻易说出口 提交于 2021-01-28 05:02:05
问题 $timeinfo = "01-‎06‎-2017 ‏‎12:34" $template = "dd-MM-yyyy HH:mm" [DateTime]::ParseExact($timeinfo, $template, $null) results in: Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime." At line:3 char:1 + [DateTime]::ParseExact($timeinfo, $template, $null) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FormatException I can't tell what is wrong here?

How to make the output in the pipeline appear on the console when running pester tests?

左心房为你撑大大i 提交于 2021-01-28 05:00:21
问题 By default, the output in the pipeline is hidden,But sometimes I really want to know the output at that time. Of course, I knew I could add additional commands, such as write-host or out-default. But does Pester itself have a mechanism to make the output display properly? I checked the help document and didn't find the relevant content, so I came here for help. 回答1: It is possible to write a custom Should wrapper (proxy) using this technique. The wrapper can write the pipeline objects to the

Exception not caught when using PowerShell command line but caught as expected when using PowerShell ISE

大憨熊 提交于 2021-01-28 05:00:02
问题 I am running PowerShell 2.0. I have a PowerShell script that adds a record to the database and returns the ID of the record added. The record ID is returned as a property called new_deal_id within a DataRow object (called ResultSet ). If there is a problem on the database end it is possible that the new_deal_id property does not get set, or doesn't exist at all. To counter this scenario I wrapped the reading of the property in a try/catch block as shown here. try { $ErrorActionPreference =

How to pause a foreach PowerShell loop

那年仲夏 提交于 2021-01-28 04:50:44
问题 I have created this simple script below to loop through a file containing a list of users and apply quota rules for each user in the file. It works, but during processing it fails sometimes as I believe the large number of users in the text file blocks access at times. Is there a way to get the loop to pause for 5 - 10 seconds after each iteration of the foreach loop or after five iterations of the foreach loop until the filer has updated those quotas completely and then move on to the next

List hard Disk Information on remote computers within a domain

旧街凉风 提交于 2021-01-28 04:17:13
问题 I am trying to get a list of hard disk information. At the moment I would only want the list to show the model of the hard disk that each computer contains. I have the below Get-WMIObject win32_diskdrive -computer (Get-Content C:\Temp\DiskDrives\Computers.txt) | Select model | Export- CSV "C:\Temp\DiskDrives\Machines.csv" The computers.txt file contains a list of computers that the code goes through one by one. The above works to a point it will list the drives that it can find for a machine

Change XML tags within PowerShell and keep content.

徘徊边缘 提交于 2021-01-28 04:16:57
问题 I have exported data from an EventLog using PowerShell and have created a sample Schema to import the data into SQL however there is an issue of the way the data is exported from PowerShell using ConvertToXML. The exports of the XML looks like this; <Property Name="Version">0</Property> <Property Name="Qualifiers" /> <Property Name="Level">0</Property> <Property Name="Task">14339</Property> <Property Name="Opcode">0</Property> <Property Name="Keywords">-9218868437227405312</Property>

Suppress Outlook pop-up allow access

偶尔善良 提交于 2021-01-28 04:16:39
问题 When running the following PowerShell code: $Outlook = New-Object -ComObject Outlook.Application $Stores = $Outlook.Session.Stores $Accounts = $Outlook.Session.Accounts $Accounts | Select-Object DisplayName, UserName, SmtpAddress, ExchangeMailboxServerName, ExchangeMailboxServerVersion A security warning pops-up: According to Microsoft there are ways around this. For instance, one can Create a COM Add-in for Outlook instead of using the Outlook COM Object as explained here. Another example of

in powershell, set affinity in start-process

删除回忆录丶 提交于 2021-01-28 03:42:55
问题 In powershell, I can launch a process with $app_name = "app.exe" $app_arguments = "arg0" Start-Process $app_name $app_arguments I try set the affinity with $app = Start-Process $app_name $app_arguments $app.ProcessorAffinity = 0x3 .... no work. In windows powershell, when I launch a process how I can set the affinity ? 回答1: I can solve with $app_name = "app.exe" $app_arguments = "arg0" $pinfo = New-Object System.Diagnostics.ProcessStartInfo $pinfo.FileName = $app_name $pinfo.Arguments = $app