Showing posts with label New-Item. Show all posts
Showing posts with label New-Item. 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”.

Friday, August 31, 2012

Setting Microsoft Office 2012 Trust Center's Trusted Location Paths using Powershell.

Hi Everyone.

If you are working in a Telecom Industry, and if your Analysts and Consultants are using in house built templates then i am sure that you are 98% facing the “Trust Centre warning”.

We are using custom in house built Office Templates for Word,Excel, and PowerPoint.  and the problem was whenever we open our in house templates is Office 2012 we were facing the below error.

We can click on it but it is a quite annoying.

31-08-2012 14-47-12

To resolved this error, the solution is to add our custom built templates directory to the  trusted location in trust center manually on every laptop and desktop.

31-08-2012 15-14-10

Did i mentioned MANUALLY???

Naaaaaa !!!!!!! I thought that we can script this.

And to resolve this is wrote a simple script. you can download the script from this link :
http://gallery.technet.microsoft.com/scriptcenter/Setting-office-2010-31d6a5f4

This script is very simple.,

You only need to provide the path of your templates or the location which you want to add as trusted to  $trustlocation variable.
$trustlocation = 'C:\Mylocation\Templates'
and that’s all , when you run the script , the script will create a location registry  named as “Location99” in to the registry.
and the Registry Keys will be look like this .
31-08-2012 15-33-48
and i have added comments in the script for easy understanding,
Functionality.
  1. First script test the path of the “Location99” registry key
  2. and if the Test path fails that will create a New Registry  Folder “Location99” and the the following registry keys
      • AllowSubfolders this is DWORD registry key and the value is 1 to allow subfolders as a trusted location too.
      • Date  = Date of creation
      • Description = Description for location etc.
      • Path  =  Path to the folder
  3. and if folder found it just write a confirmation message in the console that folder do exists.
  4. The script will do the same process for WORD,EXCEL and Powerpoint.
After running the script the location is added to the Word.
31-08-2012 15-15-24

Thanks
Aman Dhally
join aman on facebook Join aman on Linkedin follow aman on Twitter

Monday, February 13, 2012

Automate "Remote Server Administration Tools (RSAT)" Deployment using PowerShell.


HI,

These days I am working on a script which does few “Active directory” task for us. This was seems simple so for but then I have found a major hurdle comes.

Problem:

The script on which I am working will be run on newly formatted system which is having Windows7 installed. The problem was that this script will is using few “Active Directory” cmdlets. And the new installation of windows doesn’t have “RSAT” installed by default. So until or unless I don’t have “ActiveDirectory” module installed till then I can’t use my
 get-ADComputer ; get-ADComputerServiceAccount” cmdlets.

Then I thought there should be way to sort this out. So finally after spending whole day I found a way to do this within my PowerShell Script.

Solution:

The “Active Directory” module only available after installing the “Windows6.1-KB958830-x86-RefreshPkg.msu” package and then enable the “Active Directory Module for windows Powershell” in optional features.

The “Windows6.1-KB958830-x86-RefreshPkg.msu” is a “Microsoft update Standalone Package” and we can install these packages using wusa.exe {Windows Update Standalone installer}.


So after installation of the “Windows6.1-KB958830-x86-RefreshPkg.msu” we need to enable the “Active Directory Module for windows Powershell” in optional features for this we are using dism.exe { Deployment Image Servicing and Management tool}.

The Script:

·         I am placing “Windows6.1-KB958830-x86-RefreshPkg.msu” in a central location so that script the executable from it.
·         Normally I copied all the scripts in “c:\tools” folder and if that folder doesn’t exists it create it for us and write a message on screen that “C:\tools” is created.
o    $tool = test-Path C:\tools
if ($tool -eq $false ) {new-Item -Name "Tools" -Path c:\ -ItemType Directory; write-Host " folder "C:\Tools" created" -ForegroundColor Green }
·         Now it check if “Windows6.1-KB958830-x86-RefreshPkg.msu” file in exists in “C:\tools” folder and if it doesn’t exists it will copy the file from our central share folder  \\soft-server\SoftRes\$hotfix
o    hotfix = "Windows6.1-KB958830-x86-RefreshPkg.msu"
if ($testpath -eq $false) { Copy-Item \\dc3-del\PublicShare\$hotfix c:\tools\
Write-host "Files has Copied Sucessfully, Now I am going to  install the HOTFIX." -ForegroundColor RED
}
·         After copy the file from server it will install the files using wusa.exe
o    & wusa.exe "c:\tools\$hotfix" /quiet | out-null
·         After the installation finishes it will enable the “Active Directory PowerShell Module” feature in “windows Optional feature” using DISM
o    & dism.exe /Online /Enable-Feature /FeatureName:RemoteServerAdministrationTools  /FeatureName:RemoteServerAdministrationTools-Roles /FeatureName:RemoteServerAdministrationTools-Roles-AD  /FeatureName:RemoteServerAdministrationTools-Roles-AD-Powershell | Out-Null


:::::::::::::::::::::::::::::::;; Start of the script ############
$hotfix = "Windows6.1-KB958830-x86-RefreshPkg.msu"
$testpath =  test-path -path "c:\tools\$hotfix"
$tool = test-Path C:\tools
if ($tool -eq $false ) {new-Item -Name "Tools" -Path c:\ -ItemType Directory; write-Host " folder "C:\Tools" created" -ForegroundColor Green } 
if ($testpath -eq $false) { Copy-Item \\soft-server\SoftRes\$hotfix
c:\tools\
Write-host "Files has Copied Sucessfully, Now I am going to  install the HOTFIX." -ForegroundColor RED
}
Write-Host "Installing Remote Server Administration Tools...... " -ForegroundColor Yellow                  
& wusa.exe "c:\tools\$hotfix" /quiet | out-null
Write-Host "HotFix Installed, lets enable the Active Directory Features in "Optional Features"" -ForegroundColor "Green"
& dism.exe /Online /Enable-Feature /FeatureName:RemoteServerAdministrationTools  /FeatureName:RemoteServerAdministrationTools-Roles /FeatureName:RemoteServerAdministrationTools-Roles-AD  /FeatureName:RemoteServerAdministrationTools-Roles-AD-Powershell | Out-Null
Write-Host "Lets Import the Active directory PowerShell Module Now.." -BackgroundColor Green  -ForegroundColor Blue
Import-Module ActiveDirectory
write-Host "Module successfully Imported" -ForegroundColor Red -BackgroundColor White

########## End of the Script ############## 



Screenshots:
13-02-2012 20-41-20 
Note: I tested this script on Windows 7 machine and it works perfectly for me . you can download installation file of "Windows6.1-KB958830-x86-RefreshPkg.msu" from here http://www.microsoft.com/download/en/details.aspx?id=7887. Also this is a simple static script no error checking is enable in it.
 
Thanks for viewing
Aman Dhally
messenger_freak_adp1 (30)