IT Questions and Answers :)

Wednesday, January 15, 2020

What secure port does PowerShell remote utilize by default?

What secure port does PowerShell remote utilize by default?

  • 445
  • 5927
  • 5986
  • 443 
What secure port does PowerShell remote utilize by default?

 

EXPLANATION


By default PowerShell will use the following ports for communication (They are the same ports as WinRM)
TCP/5985 = HTTP
TCP/5986 = HTTPS

SOURCE

https://blogs.technet.microsoft.com/christwe/2012/06/20/what-port-does-powershell-remoting-use/
Share:

Friday, March 22, 2019

What is the scripting language that is taking over what Batch and VBS scripts used to do?

What is the scripting language that is taking over what Batch and VBS scripts used to do?

  • Java
  • C++
  • Powershell
  • VBS.Net 

 
What is the scripting language that is taking over what Batch and VBS scripts used to do?

EXPLANATION

First there were batch files, then VBscript (VBS) and now PowerShell. Sure, there have been some others along the way but, for the most part, good ol' batch, VBS and PowerShell have been the mainstays. Over the years, scripts have become not only easier to write but more powerful as well.

Anything that can be done in Batch and VBS scripts can now be done with Powershell, and more!  Check out the Powershell scripting center for numerous scripts to try out and then visit the Active Directory & GPO group to see how many Spiceheads implement them

Share:

Monday, April 9, 2018

In PowerShell, what cmdlet corresponds to the "FL" alias?

In PowerShell, what cmdlet corresponds to the "FL" alias?

  • Format-Line
  • Format-List
  • For-Loop
  • Folder-Limit 

 
In PowerShell, what cmdlet corresponds to the "FL" alias?

EXPLANATION

Format-List is the long form of the "FL" command. This command is used to change the layout of list items when they are output to the console.
For-Loop, Folder-Limit, and Format-Line are not PowerShell commands.

Share:

Wednesday, March 28, 2018

Thursday, March 8, 2018

In PowerShell, what do you call the method used to pass a hash table to a cmdlet as an argument to give it parameters?

In PowerShell, what do you call the method used to pass a hash table to a cmdlet as an argument to give it parameters?

  • Proping
  • Slamming
  • Hashing
  • Splatting 
 
In PowerShell, what do you call the method used to pass a hash table to a cmdlet as an argument to give it parameters?

EXPLANATION

Splatting can use either an array or a hash table, though it's typically used with a hash table.  The hash table is built with the key names matching the parameter names for the cmdlet, and the values being filled out with the information to pass to the respective parameter.  It's then passed as an argument to the cmdlet with the dollar ("$") decorator replaced with an at symbol ("@").
Example:
$splat = @{
    ParameterOne = 'Value to pass';
    ParameterTwo = 'Another value';
    ParameterThree = 'Still more values';
}

Get-Cmdlet @splat

# The above is equivalent to this:
Get-Cmdlet -ParameterOne 'Value to pass' -ParameterTwo 'Another value' -ParameterThree 'Still more values'
This method can be useful for making a cmdlet with a lot of parameters easier to manage.  It can also be useful for logically adding and removing parameters as needed without having to call the cmdlet multiple times, which can lead to cleaner code and faster execution time.
https://technet.microsoft.com/en-us/library/jj672955.aspx
Share:

Friday, February 16, 2018

Which of the following is NOT a PowerShell comparison operator type?

Which of the following is NOT a PowerShell comparison operator type?

  • Matching
  • Containment
  • Replacement
  • Assignment
 
 
Which of the following is NOT a PowerShell comparison operator type?

EXPLANATION

Comparison operators are used in PowerShell to compare values. There are four types of operators: equality, matching, containment, and replacement. The one big gotcha in PowerShell has to do with syntax: rather than using traditional comparison operators like < or > PowerShell uses -lt or -gt to perform comparisons.

SOURCE

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-5.1
Share:

Wednesday, January 3, 2018

Which of the following is not an automatic variable in PowerShell?

Which of the following is not an automatic variable in PowerShell?

  • $Matches
  • $Last
  • $args
  • $Error 

Which of the following is not an automatic variable in PowerShell?

EXPLANATION

While there are automatic variables for the last cmdlet executed, the last argument used in that cmdlet, and the exit status (False if it threw an error; True if it didn't), there is no automatic variable that represents the last full command, or the last command's output.  $Last is not an automatic variable in the shell.
$Error is an array that's populated by all errors output in the current session (by default, up to 256 errors, although this can be changed by changing the value in $MaximumErrorCount).
$args is an array containing any command line arguments that were passed to a function or script; it's only usable from within that function or script.  Typically, this is not used as "param()" is a lot more powerful and typically easier to work with.
$Matches is an array containing the results of the last match with regular expressions against a string.  Note that it does not get populated if the match was performed against an array; in that case, -match just outputs the matching items directly to output.

Share:

Wednesday, December 20, 2017

Which WMI class can you use to determine a system's last bootup time?

Which WMI class can you use to determine a system's last bootup time?


  • Win32_OperatingSystem
  • Win32_BootEvent
  • Win32_ComputerSystem
  • Win32_BIOS             
Which WMI class can you use to determine a system's last bootup time?

EXPLANATION

Win32_OperatingSystem includes a property called LastBootUpTime, which is the time when the system last booted up.
Win32_ComputerSystem and Win32_BIOS do not have any properties that can be used for this.
Win32_BootEvent does not exist.

Share:

Friday, December 1, 2017

In PowerShell, what is "splatting"?

Which of the following does a DNS MX record provide for a given domain?

  • The name of the inbound email server for that domain
  • The web server details of the domain
  • Outgoing email server for the domain
  • Microsoft Exchange related information for the domain 

 
In PowerShell, what is "splatting"?

EXPLANATION

When you have multiple parameters to give to a single cmdlet, you can use a "splat", also known as "splatting".  This is where you build a hash table where each key is a parameter name, and each key's value is the value that you will pass to that parameter.  Once created, you can pass the entire hash table to the cmdlet by calling it with @ instead of $.
Example:
$ADUserSplat = @{
    Department = "IT Department";
    Description = "Person in IT";
    City = "Awesometown";
}

Set-ADUser -Identity ituser @ADUserSplat
Since the splat is actually a hash table, it can be modified, added to, and removed from as a hash table, allowing more programmatic (logic based) constructions of commands, such as "only change the department if they're in one of these three groups", without having to have multiple calls to the same cmdlet in a complex if/elseif/else chain.
Share:

Thursday, November 23, 2017

Which of the following could you use while executing a PowerShell cmdlet to ignore errors?

Which of the following could you use while executing a PowerShell cmdlet to ignore errors?

  • -Action Errorignore
  • -ErrorAction Silentlycontinue
  • -Action Errorskip
  • -ErrorAction Stop 

 
Which of the following could you use while executing a PowerShell cmdlet to ignore errors?

EXPLANATION

If you want to ignore errors while executing a Powershell script, use -ErrorAction Silentlycontinue.
For more information please see the " ErrorAction parameter" section of: https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/09/handling-errors-the-powershell-way/

Share:

In PowerShell, all of the following are valid ways to create an array, except:

In PowerShell, all of the following are valid ways to create an array, except:

  • $array = %('this, 'that')
  • $array = @('this', 'that')
  • $array = ('this', 'that')
  • $array = [array]('this', 'that') 

In PowerShell, all of the following are valid ways to create an array, except:

EXPLANATION

In programming, arrays are collections of items.  In PowerShell, these items are always objects, and a single array can contain different, unrelated object types.
Typically, simply putting a comma between different items causes them to be treated together like an array.  You can also explicitly declare an array with the [array] type marker, or with the shorthand "@" symbol.
In PowerShell, the "%" symbol is an alias for "Foreach-Object", and the example above will throw an error.
Fun fact: in Perl, the "%" is used to declare a variable as a hashtable, which is similar to an array, but uses a named key index instead of an automatic number index; unlike in PowerShell, the variable prefix in Perl actually changes depending on use, so a hashtable variable would look like "%variable" instead of "$variable".
Share:

Popular Posts