Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Wednesday, 26 April 2017

Create Linux VM Using Powershell in Azure

Create Linux VM Using Powershell in Azure


  • Azure is the leading Cloud Platform today.
  • Lot of Customers are having a Hybrid setup with Cloud.
  • So With power shell now so famous lot of companies have deployed Azure CLI 2.0 to extend thier powershell skill in Cloud.
  • In Order to Create a Linux VM in cloud using powershell and CLI2.0 installed on you system use this command

az vm create -n LINUX01 -g LinuxGroup --image UbuntuLTS

  • This will create the Linux Machine called "LINUX01" with Ubuntu OS

Saturday, 28 January 2017

What is Just Enough Administration or JEA in Windows 2016

What is Just Enough Administration or JEA in Windows 2016


  • JEA is new kind of Administration Model in Windows 2016.
  • Its Role Based administration Model where you can fine tune custom Admin Settings.
  • To understand more look at the below video

Video:

Thursday, 15 September 2016

Set-DnsClientServerAddress: Powershell command to set the DNS Server

Set-DnsClientServerAddress: Powershell command to set the DNS Server


  • You need to configure the DNS Server Ip adress of the Server.
  • This will help name resolution to happen correctly.
  • To configure DNS Server Name for your network Card use "Set-DnsClientServerAddress"

Set-DnsClientServerAddress -InterfaceAlias "AdminNet" -ServerAddresses 192.168.10.2

PowerShell command to set Ipv6 IP Address


PowerShell command to step Ipv6 IP Address

  • Powershell is the most effective way to set the Ip Adress to all servers.
  • You use the New-NetIPAddress with -AddressFamily IPv6
  • This will set the Ipaddress to V6.
  • You should also mention the interface address

New-NetIPAddress -AddressFamily IPv6 -InterfaceAlias "AdminNet" `
-IPAddress 2001:db8:0:10::2 -PrefixLength 64 -DefaultGateway 2001:db8:0:10::1

New-NetIPAddress: PowerShell command to configure Static Ip Address

PowerShell command to configure Static Ip Address

  • Many times we have to configure Ipadress
  • Its usually done for servers where static ip address are given.
  • To set Static Ip adress you need to know the Network Interface for which you want to set the IP
  • To configure you use the command "New-NetIPAddress"
New-NetIPAddress -AddressFamily IPv4 -InterfaceAlias "AdminNet" `
-IPAddress 192.168.10.2 -PrefixLength 24 -DefaultGateway 192.168.10.1

  • -AddressFamily tells whether its IPV4 or IPV6
  • -InterfaceAlias tells the Name of the network.
  • -IPAddress specify the ip adress you want to configure.
  • -PrefixLength speciy the Subnet length.
  • -DefaultGateway specify the Gateway IP.

PowerShell Commmand to Disable DHCP on the Network Interface

PowerShell Commmand to Disable DHCP on the Network Interface

  • In Server we generally dont use DHCP to assign IP address.
  • We usuall set Static IP Address to Server.
  • So we need to disable the DHCP.
  • To disable DHCP from Powershell use the Command "Set-NetIPInterface" with option -DHCP Disabled

Set-NetIPInterface -InterfaceAlias "Admin" -DHCP Disabled -PassThru

  • You should specifyf or which interface you want to disable the DHCP, So you have to give the InterfaceAlias as well.

Get-NetAdapter: PowerShell Command to find Network Adapater Alias name and Index Number

PowerShell Command to find Network Adapater Alias name and Index Number


  • If you have to do changes to your Network Adapter then you need to know the Alias Name and Index Number
  • You can find those easily in PowerShell
  • The Command is "Get-NetAdapter"
  • You can see the "Name" which is Alias and ifIndex which is the "Index Number"

Wednesday, 14 September 2016

Install-ADDSDomainController: PowerShell Command to Promote a Server to Domain Controller

PowerShell Command to Promote a Server to Domain Controller




Install-ADDSDomainController -SkipPreChecks -NoGlobalCatalog:$false -CreateDnsDelegation:$false `
-CriticalReplicationOnly:$false -DatabasePath "C:\Windows\NTDS" -DomainName "Contoso.com" `
-InstallDns:$true -LogPath "C:\Windows\NTDS" NoRebootOnCompletion:$false -SiteName `
"Default-First-Site-Name" `-SysvolPath "C:\Windows\SYSVOL" -Force:$true


  • Install-ADDSDomainController will promote the Server to Domain Controller.
  • -SkipPreChecks will skip the prechecks and will procced with the install
  •  -NoGlobalCatalog:$false Will not install Global Catalog Component on this server.
  • -CreateDnsDelegation:$false Will not create DNS Delegation on this server
  • -DatabasePath tell where should be the NTDS Folder Location
  • -DomainName tell your Domain Name
  • -InstallDns:$true Installs DNS Component on the server
  • -LogPath tells the LogPath Location.
  •  NoRebootOnCompletion:$false Will not reboot the server after install.If you want to reboot make it $true
  • -SiteName Enter the AD Site name where server has to be installed
  • -SysvolPath Location of the Sysvol folder

Monday, 5 September 2016

What is Azure resource group and how to create it PowerShell

What is Azure resource group and how to create it PowerShell

What is Resource group:

  • Before deploying any resources to your subscription, you must create a resource group that will contain the resources.

Create a resource group:

  • To create a resource group, use the New-AzureRmResourceGroup cmdlet.

New-AzureRmResourceGroup -Name CognosApp -Location "West US"

  • Uses the Name parameter to specify a name for the resource group and the Location parameter to specify its location.

Connect to Specific Azure Subscription using Powershell

Connect to Specific Azure Subscription using Powershell


  • Organizations have mutiple Subscriptions, One for DEV,One for ACC and One for PROD.
  • So there are times where you want to connect to particular Subscription.
  • You have to use the command Set-AzureRmContext with SubscriptionID followed by the unique Subscription ID for the Subscription

Set-AzureRmContext -SubscriptionID <YourSubscriptionId>

How to Login to your Azure from PowerShell

How to Login to your Azure from PowerShell

  • To login to your Azure account, use the Add-AzureRmAccount cmdlet.

Add-AzureRmAccount

  • The cmdlet prompts you for the login credentials for your Azure account. 
  • After logging in, it downloads your account settings so they are available to Azure PowerShell.
  • The account settings expire, so you need to refresh them occasionally. 
  • To refresh the account settings, run Add-AzureRmAccount again.

Azure PowerShell Step By Step Tutorial

Azure PowerShell Step By Step Tutorial


What is Azure PowerShell:

  • Azure PowerShell is a set of modules that provide cmdlets to manage Azure with Windows PowerShell. 
  • You can use the cmdlets to create, test, deploy, and manage solutions and services delivered through the Azure platform. 
  • The cmdlets can be used for the same tasks as the Azure Management Portal, such as creating and configuring cloud services, virtual machines, virtual networks, and web apps.
How to Install Azure PowerShell on your Computer:



There are 2 Ways you can install Azure PowerShell

First Type:
Second Type:

  • Open PowerShell in Eleveated Prompt as Admin

Install-Module AzureRM

  • Above Command Install the Azure Resource Manager modules from the PowerShell Gallery
Install-Module Azure

  • Install the Azure Service Management module from the PowerShell Gallery

Thursday, 30 June 2016

Powershell Command to find version of OS


Powershell Command to find version of OS



  • To find which version of Windows you are running, enter the following commands in the Command Prompt or Powershell:


wmic os get caption

wmic os get osarchitecture

Saturday, 25 June 2016

PowerShell Basics for Dummies - ConvertTo-Html

PowerShell Basics for Dummies - ConvertTo-Html


ConvertTo-Html:

  • Converts Microsoft .NET Framework objects into HTML that can be displayed in a Web browser.
  • The ConvertTo-Html cmdlet converts .NET Framework objects into HTML that can be displayed in a Web browser. You can use this cmdlet to display the output of a command in a Web page.
  • You can use the parameters of ConvertTo-Html to select object properties, to specify a table or list format, to specify the HTML page title, to add text before and after the object, and to return only the table or list fragment, instead of a strict DTD page.
  • When you submit multiple objects to ConvertTo-Html, Windows PowerShell creates the table (or list) based on the properties of the first object that you submit. If the remaining objects do not have one of the specified properties, the property value of that object is an empty cell. If the remaining objects have additional properties, those property values are not included in the file.

Get-EventLog -LogName "Windows PowerShell" | ConvertTo-Html > PSEventlog.htm

  • The command sends the HTML code to the PSEventlog.htm file.

PowerShell Basics for Dummies - Get-Service

PowerShell Basics for Dummies - Get-Service


Get-Service:

  • Gets the services running on the specified computers. The default is the local computer.

 Get-Service -ComputerName "Server1"

  • This command gets the services on the "Server1" remote computer.

  • Because the ComputerName parameter of Get-Service does not use Windows PowerShell remoting, you can use this parameter even if the computer is not configured for remoting in Windows PowerShell.


Get-Service "wmi*"

  • This command retrieves services with service names that begin with WMI

Powershell Basics for Dummies - Get-ExecutionPolicy

Powershell Basics for Dummies - Get-ExecutionPolicy

Get-ExecutionPolicy

  • If you'll need to know what execution policy is in use before you attempt to run a script. You can find out by using the Get-ExecutionPolicy command.
  • This will show the current status of Execution policy.
Get-ExecutionPolicy

Four levels of security exist:

  • Restricted — Restricted is the default execution policy and locks PowerShell down so that commands can be entered only interactively. PowerShell scripts are not allowed to run.
  • All Signed — If the execution policy is set to All Signed then scripts will be allowed to run, but only if they are signed by a trusted publisher.
  • Remote Signed — If the execution policy is set to Remote Signed, any PowerShell scripts that have been locally created will be allowed to run. Scripts created remotely are allowed to run only if they are signed by a trusted publisher.
  • Unrestricted — As the name implies, Unrestricted removes all restrictions from the execution policy.

Powershell Basics for Dummies - Set-ExecutionPolicy

Powershell Basics for Dummies - Set-ExecutionPolicy

Set-ExecutionPolicy

  • By Default Microsoft has disabled scripting  in an effort to prevent malicious code from executing in a PowerShell environment. 
  • You should use Set-ExecutionPolicy command to control the level of security surrounding PowerShell scripts. 

Four levels of security exist:

  • 1. Restricted — Restricted is the default execution policy and locks PowerShell down, so that commands can be entered only interactively. PowerShell scripts are not allowed to run.
  • 2. All Signed — If the execution policy is set to All Signed then scripts will be allowed to run, but only if they are signed by a trusted publisher like Microsft etc.
  • 3.Remote Signed — If the execution policy is set to Remote Signed, any PowerShell scripts that have been locally created will be allowed to run. Scripts created remotely are allowed to run only if they are signed by a trusted publisher like Microsoft.
  • 4. Unrestricted — Unrestricted removes all restrictions from the execution policy.

You can set an execution policy by entering the Set-ExecutionPolicy command followed by the name of the policy. For example, if you wanted to allow scripts to run in an All Signed manner you could type:

Set-ExecutionPolicy All Signed

Powershell Get-Help Command Usages and uses- Powershell Basics

Powershell Get-Help Command Usages and uses


Get-Help:

  • The Help Command in PowerShell cmdlet . You can use this command to get help with any other command. For example, if you want to know how the Get-Service command works, you can type:

Get-Help -Name Get-Service
and Windows will display the full command syntax.

  • You can also use Get-Help with individual nouns and verbs. For example, to find out all the commands you can use with the Get verb, type:

Get-Help -Name Get-*

Sunday, 24 April 2016

Special Characters that can be used in Windows PowerShell output

Special Characters that can be used in Windows PowerShell output


Special Characters that can be used in Windows PowerShell output are below this will be useful when you want to include these below special characters in your output.

  • `0 -- Null
  • `a -- Alert
  • `b -- Backspace
  • `n -- New line
  • `r -- Carriage return
  • `t -- Horizontal tab
  • `' -- Single quote
  • `" -- Double quote

ADD-Content: Powershell command to add content to text file.

ADD-Content: Powershell command to add content to text file.

  • There are times when you want to ADD a content to text file after taking some actions in powershell
  • ADD-Content is the Command to use to add.
ADD-CONTENT C:\TEMP\test.txt "This is the Begning"

  • One more scenario is that you have list of text files and want to add a common thing to all then you can use the WildCards like below
$NTime=Get-Date
ADD-CONTENT C:\Temp\*.txt $Ntime

  • This will add the current date and time to all the text files in temp folder.