I am working on some utility functions to ease the administration of our O365 tenant. The thing I'm working on currently is being able to provision One Drive for Business sites for users. I have the following code that works properly so far outside of a function but once I try to make it a function, I get the error in the title. What am I doing wrong here?
Works:
$SecurePassword = Read-Host -Prompt "Please enter your password" -AsSecureString
$Context = New-Object Microsoft.SharePoint.Client.ClientContext("http://ift.tt/1AAihqO")
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($yourEmail,$SecurePassword)
$Context.Credentials = $Credentials
$Users = $Context.Web.SiteUsers
$Context.Load($Users)
$Context.ExecuteQuery()
write-host $Users.Count
Fails:
Function New-MySite{
#Not Yet Implemented
Param(
[Parameter(Mandatory=$true,HelpMessage="A comma delimited string of email addresses",Position=1)][ValidateNotNull()]
[string]$users,
[Parameter(Mandatory=$true,HelpMessage="Your email address",Position=0)][ValidateNotNull()]
[string]$yourEmail
)
$SecurePassword = Read-Host -Prompt "Please enter your password" -AsSecureString
$Context = New-Object Microsoft.SharePoint.Client.ClientContext("http://ift.tt/1AAihqO")
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($yourEmail,$SecurePassword)
$Context.Credentials = $Credentials
$Users = $Context.Web.SiteUsers
$Context.Load($Users)
$Context.ExecuteQuery()
write-host $Users.Count
}
On Powershell 3 using the Powershell ISE client. Desired usage:
New-Mysite -yourEmail "eric@domain.com" -users "user1@domain.com"
0 commentaires:
Enregistrer un commentaire