powershell

Modify the value of XML node use powershell

Deadly 提交于 2021-01-29 08:26:58
问题 I want to use the PowerShell script to modify the values in the following two paths, Use the following code to get the values. How to modify them and save them to the original file? eg: 1.Change the value of the following path to 5.0 ([xml] (Get-Content -Raw file.xml)).Map.StyleGroup.RootTopicDefaultsGroup.DefaultSubTopicShape.RightMargin 2.Change the value of the following path to false ([xml] (Get-Content -Raw file.xml)).Map.Custom.UpdatedNamedView 3.save to the original file note: use The

VSO copy to task is failing for unknown reason

百般思念 提交于 2021-01-29 08:21:05
问题 I have a visual studio team services build setup. I have 2 steps so far. Visual Studio Build - this works beautifully Copy files - this works depending on where I set the target path too. Now I need the outputted files to be deployed to our application. There are multiple tasks to use: copy files, copy and publish build artifacts, publish build artifacts, etc. I decided on copy files because it seemed the most straight forward, and after all, I just need to copy files. :) My issue is that if

How to parse XML in Powershell with Select-Xml and Xpath?

筅森魡賤 提交于 2021-01-29 08:10:38
问题 obvious output for this example would be the date and time. In the context of iterating over an xml document, how is this document correctly cast or converted to xml in Powershell dotnet core on Linux ? PS /home/nicholas/flwor> PS /home/nicholas/flwor> Select-Xml -Xml (Get-Date | ConvertTo-Xml) -XPath "/Objects/Object" Node Path Pattern ---- ---- ------- Object InputStream /Objects/Object PS /home/nicholas/flwor> PS /home/nicholas/flwor> (Get-Date | ConvertTo-Xml).OuterXml <?xml version="1.0"

Powershell script RDP connection data

懵懂的女人 提交于 2021-01-29 08:05:24
问题 I am trying to get the source network address for an RDP connection to send an email when a user connects to the server. I have everything but the source address. My script is triggered by event 1149 in the RemoteConnectionManager Operational log. I only need to access either the event data or source address from the system. $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "mail.scomage.com" $mailmessage.from = (

Copy-Item is copying unexpected folder

早过忘川 提交于 2021-01-29 08:03:47
问题 I'm struggling to understand how PowerShell handles recursion and Copy-Item command. $date=Get-Date -Format yyyyMMdd $oldfolder="c:\certs\old\$date" New-PSDrive -Name "B" -PSProvider FileSystem -Root "\\(server)\adconfig" $lastwrite = (get-item b:\lcerts\domain\wc\cert.pfx).LastWriteTime $timespan = new-timespan -days 1 -hours 1 Write-Host "testing variables..." Write-Host " date = $date" `n "folder path to create = $oldfolder" `n "timespan = $timespan" if (((get-date) - $lastwrite) -gt

Powershell script RDP connection data

陌路散爱 提交于 2021-01-29 08:03:15
问题 I am trying to get the source network address for an RDP connection to send an email when a user connects to the server. I have everything but the source address. My script is triggered by event 1149 in the RemoteConnectionManager Operational log. I only need to access either the event data or source address from the system. $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "mail.scomage.com" $mailmessage.from = (

How can I know which HDMI port is plugged in?

耗尽温柔 提交于 2021-01-29 07:55:52
问题 I have a computer with a dual hdmi output. I would like to detect which one is plugged in when I connect a monitor to either to one of them. It can be either with the help of registry, powershell or C# code, or anything. As long as it's not C++. I've tried various wmi methods. Searched the registry for anything that would specify a hdmi port. But found nothing so far. This stackoverflow answer (Detect/identify the port (HDMI, other) the monitor is connected to in Windows 7/8/10 Win32 C++) is

Read XML Attribute values based on another attribute value in the same node using Powershell

吃可爱长大的小学妹 提交于 2021-01-29 07:43:44
问题 I have a XML file file1.xml which has the data like below. <Tag1> <Tag2> <file Name="file1.rdl" Path="folder34" /> <File Name="file2.rdl" Path="folder37" /> <File Name="file3.rdl" Path="folder34" /> <File Name="File4.rdl" Path="folder76" /> <File Name="file5.rdl" Path="folder37" /> </Tag2> </Tag1> I Need a PowerShell script which will return the value of the Path attribute based on the Name attribute value. Example: If I pass the value "File4.rdl" it should return the value as "Folder76". I

Suppress automatic confirmation of deletion in powershell

試著忘記壹切 提交于 2021-01-29 07:35:04
问题 I am trying to write a silent script that deletes files older than 14 days and removes empty folders. The part that deletes files work fine, but the part that deletes folders is popping up a confirmation window no matter what I do to suppress it. Here's my code: $date=(get-date).AddDays(-14) $ConfirmPreference="None" $DebugPreference="SilentlyContinue" $ErrorActionPreference="SilentlyContinue" $ProgressPreference="SilentlyContinue" $VerbosePreference="SilentlyContinue" $WarningPreference=

Powershell to Split huge folder in multiple folders

人盡茶涼 提交于 2021-01-29 07:24:12
问题 I have a folder that contains many huge files. I want to split these files in 3 folders. The requirement is to get the count of files in main folder and then equally split those files in 3 child folders. Example - Main folder has 100 files. When I run the powershell, 3 child folders should be created with 33, 33 and 34 files respectively. How can we do this using Powershell? I've tried the following: $FileCount = (Get-ChildItem C:\MainFolder).count Get-ChildItem C:\MainFolder -r | Foreach