Переименование компьютеров удаленно через powershell [Remote rename computers by powershell]

PowerShell Scrtips, Process automation

 

PowerShell Regex To Get Value Between Quotation Marks

HowTo, PowerShell Scrtips
SOURCE: https://workingsysadmin.com/quick-tip-powershell-regex-to-get-value-between-quotation-marks/

If you’ve got a value like the following…

 

… that maybe came from the body of a file, was returned by some other part of a script, etc., and you just want the portions that are actually between the quotes, the quickest and easiest way to get it is through a regular expression match.

That’s right, forget splitting or trimming or doing other weird string manipulation stuff. Just use the [regex]::matches() feature of PowerShell to get your values.

Matches takes two parameters. 1. The value to look for matches in, in this case the here-string in my $s variable, and 2. The regular expression to be used for matching. Since Matchesreturns a few items, we are making sure to just select the value for each match.

So what is that regex doing? Let’s break it down into it’s parts.

  • (?<=\”) this part is a look behind as specified by the ?<= part. In this case, whatever we are matching will come right after a quote. Doing the look behind prevents the quotation mark itself from actually being part of the matched value. Notice I have to escape the quotation mark character.
  • .+? this part basically matches as many characters as it takes to get to whatever the next part of the regex is. Look into regex lazy mode vs greedy mode.
  • (?=\”) this part is a look ahead as specified by the ?= part. We’re looking ahead for a quotation mark because whatever comes after our match is done will be a quotation mark.

So basically what we’ve got is “whatever comes after a quotation mark, and as much of that as you need until you get to another quotation mark”. Easy, right? Don’t you love regex?

POWERSHELL SPECIAL CHARACTERS

HowTo, PowerShell Scrtips

Source: https://www.sconstantinou.com/powershell-special-characters/

POWERSHELL SPECIAL CHARACTERS

As in every programming and scripting language, in PowerShell there are special characters that you can use to represent characters, that we are not able to find in the standard set. In this tutorials we will see those PowerShell special Characters and what is their use.

All special characters in PowerShell start with backtick ( ). You can use the special characters only within double quotes ( " " ). If they are used otherwise, they will not be interpreted to the desired one. First of all we will see the list of characters and then we will go through it to see more details for each of the special characters. The list is provided by Microsoft.

Special Characters List:

POWERSHELL RESERVED WORDS

Uncategorized

POWERSHELL RESERVED WORDS

In this tutorial we will see the list of PowerShell reserved words. As in every programming / scripting language there are some words that have special meaning. In my opinion, you should avoid using those words for other purposes. This will help you avoid undesired results when you are programming / scripting. In PowerShell there is also such a list and you are able to see it below:

RESERVED WORDS

ALREADY IN USE

  • assebly
  • base
  • begin – Specifies one part of the body of a function, along with the DynamicParam, Process, and End keywords. The Begin statement list runs one time before any objects are received from the pipeline.
  • break – Causes a script to exit a loop.
  • catch – Specifies a statement list to run if an error occurs in the accompanying Try statement list. An error type requires brackets. The second pair of brackets indicates that the error type is optional.
  • class – Specifies a new class in PowerShell.
  • command
  • configuration
  • continue – Causes a script to stop running a loop and to go back to the condition. If the condition is met, the script begins the loop again.
  • data – In a script, defines a section that isolates data from the script logic. Can also include If statements and some limited commands.
  • do – Used with the While or Until keyword as a looping construct. Windows PowerShell runs the statement list at least one time, unlike a loop that uses While.
  • dynamicparam – Specifies one part of the body of a function, along with the Begin, Process, and End keywords. Dynamic parameters are added at run time.
  • else – Used with the If keyword to specify the default statement list.
  • elseif – Used with the If and Else keywords to specify additional conditionals. The Else keyword is optional.
  • end – Specifies one part of the body of a function, along with the DynamicParam, Begin, and End keywords. The End statement list runs one time after all the objects have been received from the pipeline.
  • enum – It is used to declare an enumeration; a distinct type that consists of a set of named labels called the enumerator list.
  • exit – Causes PowerShell to exit a script or a PowerShell instance.
  • filter – Specifies a function in which the statement list runs one time for each input object. It has the same effect as a function that contains only a Process block.
  • finally – Defines a statement list that runs after statements that are associated with Try and Catch. A Finally statement list runs even if you press CTRL+C to leave a script or if you use the Exit keyword in the script.
  • for – Defines a loop by using a condition.
  • foreach – Defines a loop by using each member of a collection.
  • function – Creates a named statement list of reusable code. You can name the scope a function belongs to. And, you can specify one or more named parameters by using the Param keyword. Within the function statement list, you can include DynamicParam, Begin, Process, and End statement lists.
  • hidden – Hides class members from the default results of the Get-Member cmdlet, and from IntelliSense and tab completion results.
  • if – Defines a conditional.
  • in – Used in a ForEach statement to create a loop that uses each member of a collection.
  • inlinescript – Runs workflow commands in a shared PowerShell session. This keyword is valid only in a PowerShell Workflow.
  • interface
  • module
  • namespace
  • parallel
  • param – Defines the parameters in a function.
  • private
  • process – Specifies a part of the body of a function, along with the DynamicParam, Begin, and End keywords. When a Process statement list receives input from the pipeline, the Process statement list runs one time for each element from the pipeline. If the pipeline provides no objects, the Process statement list does not run. If the command is the first command in the pipeline, the Process statement list runs one time.
  • public
  • return – Causes PowerShell to leave the current scope, such as a script or function, and writes the optional expression to the output.
  • sequence
  • static – Specifies the property or method defined is common to all instances of the class in which is defined.
  • switch – To check multiple conditions, use a Switch statement. The Switch statement is equivalent to a series of If statements, but it is simpler. The Switch statement lists each condition and an optional action. If a condition obtains, the action is performed.
  • throw – Throws an object as an error.
  • trap – Defines a statement list to be run if an error is encountered. An error type requires brackets. The second pair of brackets indicates that the error type is optional.
  • try – Defines a statement list to be checked for errors while the statements run. If an error occurs, PowerShell continues running in a Catch or Finally statement. An error type requires brackets. The second pair of brackets indicates that the error type is optional.
  • type
  • until – Used in a Do statement as a looping construct where the statement list is executed at least one time.
  • using – Allows to indicate which namespaces are used in the session. Classes and members require less typing to mention them. You can also include classes from modules.
  • while – Used in a Do statement as a looping construct where the statement list is executed at least one time.
  • workflow

Application 11402 Setup cannot open the registry key

Administration Issues, Fixes, PowerShell Scrtips

Error message:

Product: Microsoft Office 32-bit Components 2016 — Error 1402. Setup can not open the registry key UNKNOWN \ Components \ 6AF6D649BB945143DAD2D436C434C20F \ 000061091C0000000100000000F01FEC. Microsoft Support Services (PSS) for assistance. For information about how to contact PSS, see Temp \ Setup00003478 \ PSS10R.CHM.

 

The problem is that in the section hklm: \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Installer \ UserData \ S-1-5-18 \ Components »
there are sections «000061091C0000000100000000F01FEC», change and reading of which are not possible. For some reason, the credentials for these sections have been changed, which are not owned by the administrator.

Solve the problem, go into each section, change the owner and assign authority. Find out exactly where in which sections, it is very difficult. A total of 108024 sections, within each of them there may be a problematic section.

Decision:

I made a backup copy of the registry keys «hklm: \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Installer \ UserData \ S-1-5-18 \ Components»
Deleted all registry keys. There will be keys to which there is no access.
Formed the scenario:

 

SetACL.exe can be found here

 

4. Imported registry keys

5. Performed the reinstallation of Office

message tracking log

HowTo, PowerShell Scrtips

 

Get MAC addresses and update list

Uncategorized

 

Add Days, Hours, and Minutes to Current Time

HowTo

PowerTip: Add Days, Hours, and Minutes to Current Time