header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Newbie question - script doesn't give any output.
Last Post 03 Jul 2010 04:25 AM by Zaicnupagadi. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
ZaicnupagadiUser is Offline
New Member
New Member
Posts:9
Avatar

--
02 Jul 2010 01:33 PM
    Hi to all,

    I have copied this script from site and doesn't work for me. I want to have listed all of shares from some remote servers with rights to them also.

    function Get-MyShares
    {
     param([string]$Server)
     $Shares = Get-WmiObject -Class Win32_Share -ComputerName $Server
     $output = @()
     ForEach ($Share in $Shares)
     {
      $fullpath = “\\{0}\{1}” -f $server, $share.name
      Add-Member -MemberType NoteProperty -InputObject $Share -Name FullPath -Value $fullpath
      $output += $Share
     }
     Return $output
    }}


    I have tried to make some modyfications but on this moment i don't even know much about loops in powershell. So I simply pasted the code I'm trying to use. If somedoby can help will be great.
    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    02 Jul 2010 02:02 PM
    Yup, this is just a function, not a full script.  In order to make it work you'll need to specify a bit more after the function:

    ### Script Begin ###

    function Get-MyShares
    {
     param([string]$Server)
     $Shares = Get-WmiObject -Class Win32_Share -ComputerName $Server
     $output = @()
     ForEach ($Share in $Shares)
     {
      $fullpath = “\\{0}\{1}” -f $server, $share.name
      Add-Member -MemberType NoteProperty -InputObject $Share -Name FullPath -Value $fullpath
      $output += $Share
     }
     Return $output
    }}

    Get-MyShares "ServerNameHere"

    ### Script End ###

    Or convert this to a ps1 and run it similarly from the console

    ### Script Begin ###
    param([string]$Server)

    $Shares = Get-WmiObject -Class Win32_Share -ComputerName $Server

    $output = @()

    ForEach ($Share in $Shares) {
      $fullpath = “\\{0}\{1}” -f $server, $share.name
      Add-Member -MemberType NoteProperty -InputObject $Share -Name FullPath -Value $fullpath
      $output += $Share
    }
    $output
    ### Script End ###
    and call it ina similar manor from the console
    .\Get-MyShares.ps1 -server "ServerNameHere"
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    ZaicnupagadiUser is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    03 Jul 2010 04:25 AM
    Many thanks for help!! :)
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer