locked
Please Help! RRS feed

  • Question

  • Hi

    Im a newbie in Powershell. I trying to run a script on AD server, this script is suppose to create a Sheard Folder on around 200 servers (in the same network and domain ofcourse) and allow only Domain Admins group to have access (Full access) to it. This script fetches the list of server names from a text file in the same dir. named CompList.txt 

    Below is the code, please let me know what am i doing wrong\missing. Am I missing "ForEach command, if yes then how can i use it here.

    $computername=Get-Content "C:\CreatFldr\CompList.txt"
    $credentials=Get-Credential -Credential Domain.com\Username

    Enter-PSSession -ComputerName $computername -Credential $credentials
    NEW-ITEM C:\AdminShare -type Directory
    $Shares = [WMICLASS]”WIN32_Share”
    $Shares.Create(“C:\AdminShare”,0)

    icacls c:\AdminShare /grant "Domain.com/Domain Admins":F

    Exit

    Wednesday, August 8, 2012 1:07 PM

Answers

  • Hi

    You can try

    ForEach ($computer in $computername)
    {

    $credentials=Get-Credential -Credential Domain.com\Username

    Enter-PSSession -ComputerName $computername -Credential $credentials
    NEW-ITEM C:\AdminShare -type Directory
    $Shares = [WMICLASS]”WIN32_Share”
    $Shares.Create(“C:\AdminShare”,0)

    icacls c:\AdminShare /grant "Domain.com/Domain Admins":F

    Exit


    }


    Thanks, Swapnil Prajapati

    • Marked as answer by Kevin Remde Sunday, December 2, 2012 7:30 PM
    Tuesday, August 21, 2012 4:18 AM

All replies

  • Why not using net use g: \\servername\filename

    use cmd batch scripts better :)

      

    Guowen Su
    Cisco Certified Network Associate
    Cisco Certified Internetwork professional - MPLS
    Certified Information Systems Security Professional
    Microsoft Partner Network 2011
    Microsoft Certified Professional
    Microsoft Certified Systems Administrator:Security
    Microsoft Certified Systems Engineer: Security
    Microsoft Certified Technology Specialist: Windows Server 2008 Active Directory, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Network Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows Server 2008 Applications Infrastructure, Configuration
    Microsoft Certified Technology Specialist: Windows 7, Configuring
    Microsoft Certified IT Professional: Enterprise Administrator
    Microsoft Certified IT Professional: Server Administrator
    Certified Ethical Hacker
    Computer Hacking Forensics Investigator
    Certified Sonicwall Security Administrator
    Microsoft Geeks

    • Proposed as answer by Soh.M Friday, August 10, 2012 1:44 AM
    Friday, August 10, 2012 1:44 AM
  • Hi

    You can try

    ForEach ($computer in $computername)
    {

    $credentials=Get-Credential -Credential Domain.com\Username

    Enter-PSSession -ComputerName $computername -Credential $credentials
    NEW-ITEM C:\AdminShare -type Directory
    $Shares = [WMICLASS]”WIN32_Share”
    $Shares.Create(“C:\AdminShare”,0)

    icacls c:\AdminShare /grant "Domain.com/Domain Admins":F

    Exit


    }


    Thanks, Swapnil Prajapati

    • Marked as answer by Kevin Remde Sunday, December 2, 2012 7:30 PM
    Tuesday, August 21, 2012 4:18 AM