Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
General PowerShell
Newbie question - script doesn't give any output.
Last Post 03 Jul 2010 04:25 AM by
Zaicnupagadi
. 2 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
Zaicnupagadi
New Member
Posts:9
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.
PoSherLife
Basic Member
Posts:364
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
Zaicnupagadi
New Member
Posts:9
03 Jul 2010 04:25 AM
Many thanks for help!! :)
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2