This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$path = "C:\Testing\File.xml" | |
[Xml]$servicefactoryconfig = Get-Content -Path $path -Raw | |
$old = $servicefactoryconfig.SelectSingleNode("/factory/map/add[@key='Audit']") | |
$parent = $old.ParentNode | |
[void] $parent.RemoveChild($old) | |
$newNode = [Xml] @' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$csvFileName = 'C:\My\Input.csv' | |
# Example 3 - Using the -match operator with a more complex regular expression to extract the IP address | |
Import-Csv -Path $csvFileName | | |
ForEach-Object { | |
if ($PSItem.URL -match '(?<IPAddress>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})') { | |
$Matches.IPAddress | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Translate DISM feature names to PowerShell | |
$translationTable = @' | |
NetFx4ServerFeatures | |
NetFx4 | |
NetFx4Extended-ASPNET45 | |
IIS-WebServerRole | |
IIS-WebServer | |
IIS-CommonHttpFeatures | |
IIS-Security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var script = System.IO.File.ReadAllText(textBoxScriptToRun.Text); | |
var match = Regex.Match(script, "function (?<FunctionName>[a-z]+-[a-z0-9]+)", | |
RegexOptions.IgnoreCase); | |
var functionName = match.Groups["FunctionName"]; | |
Hashtable functionParams = new Hashtable(); | |
foreach (var line in textBoxParameters.Lines) | |
{ | |
var tokens = line.Split("=".ToCharArray(), 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$logFileContent = Get-Content -Path C:\My\Forum\mail.log -Raw | |
$regExMatches = [regex]::Matches($logFileContent, '(?<timestamp>[0-9/: ]+)\tUser (?<email>[a-z0-9@.]+) logged on') | |
$items = $regExMatches | ForEach-Object { | |
[PSCustomObject]@{ | |
timestamp = [DateTime]$_.Groups['timestamp'].value | |
email = $_.Groups['email'].Value | |
} | |
} | |
$items | Group-Object -Property email | Select-Object -Property Name, Count | Sort-Object -Property Count -Descending |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$osInfo = Get-WmiObject -Class Win32_OperatingSystem -Property Name | |
# Using the PowerShell -split operator to split the string into an array | |
# and output the first array item containing the operating system name | |
($osInfo.Name -split '\|')[0] | |
# Using the Split method of the .NET String class to split the string into an array | |
# and output the first array item containing the operating system name | |
$osInfo.Name.Split('|')[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clear-Host | |
$file = Get-Content -Path 'X' # List of Computers | |
$fileName = 'X' + (Get-Date -Format dd.MM.yyyy) + '.HTML' | |
foreach ($node in $file) { | |
$selectObjectProperties = @( | |
'SystemName' | |
'DeviceID' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$text = '[email protected]' | |
# Example 1: Unnamed capturing group | |
if ($text -match '@(.+)$') { | |
# Output the complete match | |
$Matches[0] # @example.com | |
# Output only the value of the capturing group | |
$Matches[1] # example.com | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$crlf = [System.Environment]::NewLine | |
[string] $TNS = 'LINKED_SERVER' | |
$sqlfiles = "c:\temp\script1.sql", "c:\temp\script2.sql" | |
$connection=New-Object DATA.OracleClient.OracleConnection("Data Source=$TNS;User Id=TEST;Password=XXXXXXXX") | |
foreach ($sqlfile in $sqlfiles){ | |
$FileLines = Get-Content $sqlfile | |
$query = [string]::Join($crlf,$FileLines) | |
#log start time |
NewerOlder