Showing posts with label Manage Windows Sevrer 2012 R2 by using PowerShell. Show all posts
Showing posts with label Manage Windows Sevrer 2012 R2 by using PowerShell. Show all posts

Monday, July 13, 2015

Managing Windows Server 2012 R2 Using PowerShell : Part-10 : Creating New File Shares.

  1. Part 1 : Windows Server 2012 R2 Installation.
  2. Part 2 : Exploring PowerShell Default Settings.
  3. Part 3 : Getting and setting server name.
  4. Part 4 : Getting IP Address of the server.
  5. Part 5 : Setting IP Address of the server.
  6. Part 6 : Checking if Server is member of domain.
  7. Part 7 : Joining Server to the domain.
  8. Part 8 : Magic of PowerShell PSRemoting..
  9. Part 9 : Installing Windows Features and Roles

6-24-2015 12-42-00 PM

Part - 10 : Creating new File Shares.

There is one particular task which every I.T. Admin does on their server. Guess what it is?

It's creating network shares on server. Creating new network shares in Server2012R2 are very easy. We simple need to use the cmdlet  New-SmbShare .

Let's create  a network share folder using PowerShell. Before setup sharing, we need to create a folder first.

In the below command, we are creating a new folder using  New-Item cmdlet, we are creating a folder name ''MarketingImages" , and creating it in the 'C:\' drive root.

New-Item -Path 'C:\' -Name 'MarketingImages' -Type Directory

Aman Dhally - Manya Kaur

Aman Dhally - Manya Kaur

In the above screenshot, you can see that our folder have created successfully.

Now, we need to share it, we do use the New-SmbShare cmdlet for sharing the folder. In the below command,  in -Name we have provide the sharing name , which is "Makrting Images" ,-Path in we have give the physical path of the folder which is C:\MarketingImages, We are giving the  read only access to everyone, so we used  -ReadAccess "Everyone", I am using the AccessBased in -FolderEnumeration Mode, and in -Description, I have provided a description about the folder.

New-SmbShare -Name "Makrting Images" -Path C:\MarketingImages -ReadAccess "Everyone" -FolderEnumerationMode AccessBased -Description "This contains the royalty free images"

 

Aman Dhally - Manya Kaur

 

Our above command has run successfully, lets see if the folder is shared and accessible..

 

 

Aman Dhally - Manya Kaur

 

Aman Dhally - Manya Kaur

Yayy!!! it's done! Cool!

To know more about New-SmbShare visit this link : https://technet.microsoft.com/en-us/library/jj635722(v=wps.630).aspx 

That's all for today, see you in next blog post.

Aman Dhally - Manya Kaur

Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

Wednesday, June 24, 2015

Managing Windows Server 2012 R2 Using PowerShell : Part-8 : The magic of Windows PowerShell PSRemoting.

 

  1. Part 1 : Windows Server 2012 R2 Installation.
  2. Part 2 : Exploring PowerShell Default Settings.
  3. Part 3 : Getting and setting server name.
  4. Part 4 : Getting IP Address of the server.
  5. Part 5 : Setting IP Address of the server.
  6. Part 6 : Checking if Server is member of domain.
  7. Part 7 : Joining Server to the domain.

Part -8 : The magic of Windows PowerShell PSRemoting.

6-24-2015 12-42-00 PM

Welcome back,

In the pervious blog post, we added our Windows 2012 R2 server to the domain by using Windows PowerShell, I think, our most of work is done on the server, now to do everything else on server we are going to use Windows PowerShell PSRemoting to done our jobs.

What is "Windows PowerShell PSRemoting"?

In simple words, by using PowerShell PSRemoting, we can run command on our server remotely, or we can also connect to their PowerShell console locally (  kind of SSH thing Winking smile ).

Do I need to enable PSRemoting on Windows 2012 R2 server?

In the Part-2 of this series, we noticed that PSRemoting is enabled by default on Windows 2012 R2 servers.

How to use it?

It is very simple to use.

In the below screenshot, you can see, two of PowerShell consoles, one is opening on Server ( to show you it's computer name, ) and second one is opened on my laptop.Just to show you that we are going to use client PowerShell console, not the server's.

PowerShell tip :
You can use the $env:COMPUTERNAME to find the computer name.

1

Now on your client machine, create a $credential variable and store our admin account's username and password in to it by using Get-Credential cmdlet (if you remember, we done the same thing in our previous blog post) .

$credential = Get-Credential

2

Now, we need to create another variable to store the PowerShell PSRemoting session information.

In the below command, are are creating a $session variable, and then we are using New-PSSession cmdlet to initiate a session ,in -ComputerName , we have provided the name of our server , and in -Credential we are provided the name of  variable $credential in which we have stored our admin username and password credential information.

$session = New-PSSession -ComputerName 'DEL-2k12' -Credential  $credential

3

No errors! Great!

All heavy lifting is done. Now, we only need to type Enter-PSSession cmdlet , provide the name of session, which is $session  in my case and hit enter. That's all.

Enter-PSSession -Session $session

4

In the above screenshot, you can see,that we are successfully connected to our server and  we are on remote PowerShell console of our windows 2012 R2 Server, you can also see that prompt of PowerShell has also changed too and when I run the ,$env:COMPUTERNAME it give us the name of server.

If you want to exit from your remoting session, just type and run the Exit-PSSession cmdlet.

5

PowerShell Tip:
By default PowerShell use TCO Port, 5985,5986 for PSRemoting.

Basic troubleshooting.

Some tips for PSRemoting trouble shootings are :

  1. Make sure port 5985, 5986 is opened on the server or not blocked by something else.
  2. Make sure WinRm Service is running .
  3. Try to run Enable-PSRemoting -Force on server.

That's all for now and I am hoping that you have enjoyed this post.

tumblr_ma3iifkEXw1r19a45o2_250

Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.