Skip to content

Commit

Permalink
Merge pull request #198 from PowerShell/release-v0.12
Browse files Browse the repository at this point in the history
Release v0.12
  • Loading branch information
KarolKaczmarek committed Mar 28, 2016
2 parents e49628b + 58de03d commit 50d7769
Show file tree
Hide file tree
Showing 140 changed files with 4,172 additions and 1,562 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.suo
*.user
*.coverage
.vs
.vs
.psproj
.sln
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell",
"type": "PowerShell",
"request": "launch",
"program": "RunPesterTests.ps1"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)] [System.String] $WebAppUrl,
[parameter(Mandatory = $true)] [ValidateSet("Default","Intranet","Extranet","Custom","Internet")] [System.String] $Zone,
[parameter(Mandatory = $false)] [System.String] $Url,
[parameter(Mandatory = $true)] [ValidateSet("Present","Absent")] [System.String] $Ensure,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount

)

Write-Verbose -Message "Getting Alternate URL for $Zone in $WebAppUrl"

$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]

$aam = Get-SPAlternateURL -WebApplication $params.WebAppUrl -Zone $params.Zone | Select -First 1
$url = $null
$Ensure = "Absent"
if ($aam -ne $null) {
$url = $aam.PublicUrl
$Ensure = "Present"
}

return @{
WebAppUrl = $params.WebAppUrl
Zone = $params.Zone
Url = $url
Ensure = $Ensure
InstallAccount = $params.InstallAccount
}
}
return $result
}

function Set-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)] [System.String] $WebAppUrl,
[parameter(Mandatory = $true)] [ValidateSet("Default","Intranet","Extranet","Custom","Internet")] [System.String] $Zone,
[parameter(Mandatory = $false)] [System.String] $Url,
[parameter(Mandatory = $true)] [ValidateSet("Present","Absent")] [System.String] $Ensure,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount

)

$CurrentValues = Get-TargetResource @PSBoundParameters

Write-Verbose -Message "Updating app domain settings for $SiteUrl"

if ($Ensure -eq "Present") {
if ([string]::IsNullOrEmpty($Url)) {
throw "URL must be specified when ensure is set to present"
}

Invoke-xSharePointCommand -Credential $InstallAccount -Arguments ($PSBoundParameters, $CurrentValues) -ScriptBlock {
$params = $args[0]
$CurrentValues = $args[1]

if ([string]::IsNullOrEmpty($CurrentValues.Url)) {
New-SPAlternateURL -WebApplication $params.WebAppUrl -Url $params.Url -Zone $params.Zone
} else {
Get-SPAlternateURL -WebApplication $params.WebAppUrl -Zone $params.Zone | Set-SPAlternateURL -Url $params.Url
}
}
} else {
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]
Get-SPAlternateURL -WebApplication $params.WebAppUrl -Zone $params.Zone | Remove-SPAlternateURL -Confirm:$false
}
}
}

function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)] [System.String] $WebAppUrl,
[parameter(Mandatory = $true)] [ValidateSet("Default","Intranet","Extranet","Custom","Internet")] [System.String] $Zone,
[parameter(Mandatory = $false)] [System.String] $Url,
[parameter(Mandatory = $true)] [ValidateSet("Present","Absent")] [System.String] $Ensure,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount

)

if ([string]::IsNullOrEmpty($Url) -and $Ensure -eq "Present") {
throw "URL must be specified when ensure is set to present"
}

$CurrentValues = Get-TargetResource @PSBoundParameters
Write-Verbose -Message "Testing alternate URL configuration"
return Test-xSharePointSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("Url", "Ensure")
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
**Description**

This resource is used to define an alternate access mapping URL for a specified web application.


**Example**

xSPAlternateUrl CentralAdminAAM
{
WebAppUrl = "http://sharepoint1:9999"
Zone = "Intranet"
Url = "https://admin.sharepoint.contoso.com"
PsDscRunAsCredential = $SPSetupAccount
}
*/

[ClassVersion("1.0.0.0"), FriendlyName("xSPAlternateUrl")]
class MSFT_xSPAlternateUrl : OMI_BaseResource
{
[Key, Description("The URL of the web application to apply the alternate URL to")] String WebAppUrl;
[Key, Description("The Zone to use for the alternate URL"), ValueMap{"Default","Intranet","Extranet","Custom","Internet"}, Values{"Default","Intranet","Extranet","Custom","Internet"}] String Zone;
[Write, Description("The new alternate URL")] String Url;
[Required, Description("Present ensures the URL is set for this zone on this web app, Absent ensures it is removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsAccount if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ Note that this will not scan documents for viruses on it's own, an external tool
[ClassVersion("1.0.0.0"), FriendlyName("xSPAntivirusSettings")]
class MSFT_xSPAntivirusSettings : OMI_BaseResource
{
[Key] Boolean ScanOnDownload;
[Write] Boolean ScanOnUpload;
[Write] Boolean AllowDownloadInfected;
[Write] Boolean AttemptToClean;
[Write] Uint16 TimeoutDuration;
[Write] Uint16 NumberOfThreads;
[Write, EmbeddedInstance("MSFT_Credential")] String InstallAccount;
[Key, Description("Should documents be scanned before being downloaded")] Boolean ScanOnDownload;
[Write, Description("Should documents be scanned on upload")] Boolean ScanOnUpload;
[Write, Description("Should documents that are infected be allowed to be downloaded")] Boolean AllowDownloadInfected;
[Write, Description("Should infected documents be handed to the AV engine to attempt cleaning")] Boolean AttemptToClean;
[Write, Description("What is the timeout for an AV scan in seconds")] Uint16 TimeoutDuration;
[Write, Description("How many concurrent threads should the AV engine be able to run on a server")] Uint16 NumberOfThreads;
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsAccount if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ The catalog site needs to have been created using the correct template (APPCATAL
[ClassVersion("1.0.0.0"), FriendlyName("xSPAppCatalog")]
class MSFT_xSPAppCatalog : OMI_BaseResource
{
[Key] string SiteUrl;
[Write, EmbeddedInstance("MSFT_Credential")] String InstallAccount;

[Key, Description("The URL of the site collection that will be the app catalog for the web app that it is in")] string SiteUrl;
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsAccount if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ You can set the domain name and the prefix that is to be used for app URLs.
[ClassVersion("1.0.0.0"), FriendlyName("xSPAppDomain")]
class MSFT_xSPAppDomain : OMI_BaseResource
{
[Key] string AppDomain;
[Required] string Prefix;
[Write, EmbeddedInstance("MSFT_Credential")] String InstallAccount;
[Key, Description("The domain name for apps to use in this farm")] string AppDomain;
[Required, Description("The prefix to go on to app URLs")] string Prefix;
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsAccount if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;

};
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Database names or server name will not be changed if the configuration does not
[ClassVersion("1.0.0.0"), FriendlyName("xSPAppManagementServiceApp")]
class MSFT_xSPAppManagementServiceApp : OMI_BaseResource
{
[Key] string Name;
[Required] String ApplicationPool;
[Write] string DatabaseName;
[Write] String DatabaseServer;
[Write, EmbeddedInstance("MSFT_Credential")] String InstallAccount;
[Key, Description("The name of the app management service application")] string Name;
[Required, Description("The app pool that should be used to run the service app")] String ApplicationPool;
[Write, Description("The name of the database for the service application")] string DatabaseName;
[Write, Description("The name of the server for the database")] String DatabaseServer;
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsAccount if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};

Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Database names or server name will not be changed if the configuration does not
[ClassVersion("1.0.0.0"), FriendlyName("xSPBCSServiceApp")]
class MSFT_xSPBCSServiceApp : OMI_BaseResource
{
[Key] string Name;
[Required] String ApplicationPool;
[Write] string DatabaseName;
[Write] String DatabaseServer;
[Write, EmbeddedInstance("MSFT_Credential")] String InstallAccount;
[Key, Description("The name of the BCS service app")] string Name;
[Required, Description("The application pool it should run in")] String ApplicationPool;
[Write, Description("Name of the database to create for the service app")] string DatabaseName;
[Write, Description("Name of the database server to host the database on")] String DatabaseServer;
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsAccount if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ This resource is used to set the "super user" and "super reader" cache accounts
[ClassVersion("1.0.0.0"), FriendlyName("xSPCacheAccounts")]
class MSFT_xSPCacheAccounts : OMI_BaseResource
{
[Key] string WebAppUrl;
[Required] string SuperUserAlias;
[Required] string SuperReaderAlias;
[Write, EmbeddedInstance("MSFT_Credential")] String InstallAccount;
[Key, Description("The URL of the web application to set the accounts for")] string WebAppUrl;
[Required, Description("The account name for the super user")] string SuperUserAlias;
[Required, Description("The account name fo the super reader")] string SuperReaderAlias;
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsAccount if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};

Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ This means you need to use [xSPDistributedCacheService](xSPDistributedCacheServi
[ClassVersion("1.0.0.0"), FriendlyName("xSPCreateFarm")]
class MSFT_xSPCreateFarm : OMI_BaseResource
{
[Key] String FarmConfigDatabaseName;
[Key] String DatabaseServer;
[Required, EmbeddedInstance("MSFT_Credential")] String FarmAccount;
[Write, EmbeddedInstance("MSFT_Credential")] String InstallAccount;
[Required] String Passphrase;
[Required] String AdminContentDatabaseName;
[Write] uint32 CentralAdministrationPort;
[Write, ValueMap{"Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd"}, Values{"Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd"}] string ServerRole;
[Key, Description("Name of the configuration database")] String FarmConfigDatabaseName;
[Key, Description("Server that will host the configuration and admin content databases")] String DatabaseServer;
[Required, Description("The account to use as the main farm account"), EmbeddedInstance("MSFT_Credential")] String FarmAccount;
[Required, Description("The passphrase to use to allow servers to join this farm")] String Passphrase;
[Required, Description("The name of the admin content database")] String AdminContentDatabaseName;
[Write, Description("What port will Central Admin be provisioned to - default is 9999")] uint32 CentralAdministrationPort;
[Write, Description("SharePoint 2016 only - the MinRole role to enroll this server as"), ValueMap{"Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd"}, Values{"Application","Custom","DistributedCache","Search","SingleServer","SingleServerFarm","SpecialLoad","WebFrontEnd"}] string ServerRole;
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsAccount if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)] [System.String] $DatabaseName,
[parameter(Mandatory = $true)] [System.String] $AGName,
[parameter(Mandatory = $false)] [System.String] $FileShare,
[parameter(Mandatory = $true)] [ValidateSet("Present","Absent")] [System.String] $Ensure,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

Write-Verbose -Message "Getting current AAG config for $DatabaseName"

$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]

$database = Get-SPDatabase | Where-Object { $_.Name -eq $params.DatabaseName }

$Ensure = "Absent"
$AGName = $params.AGName
if ($database -ne $null) {
$ag = $database.AvailabilityGroup
if ($ag -ne $null) {
$AGName = $ag.Name
if ($ag.Name -eq $params.AGName) {
$Ensure = "Present"
}
}
}

return @{
DatabaseName = $params.DatabaseName
AGName = $AGName
FileShare = $params.FileShare
Ensure = $Ensure
InstallAccount = $params.InstallAccount
}
}
return $result
}

function Set-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)] [System.String] $DatabaseName,
[parameter(Mandatory = $true)] [System.String] $AGName,
[parameter(Mandatory = $false)] [System.String] $FileShare,
[parameter(Mandatory = $true)] [ValidateSet("Present","Absent")] [System.String] $Ensure,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

Write-Verbose -Message "Setting AAG config for $DatabaseName"

$CurrentValues = Get-TargetResource @PSBoundParameters

# Move to a new AG
if ($CurrentValues.AGName -ne $AGName -and $Ensure -eq "Present") {
Write-Verbose -Message "Moving $DatabaseName from previous AAG to $AGName"
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments ($PSBoundParameters, $CurrentValues) -ScriptBlock {
$params = $args[0]
$CurrentValues = $args[1]

# Remove it from the current AAG first
Remove-DatabaseFromAvailabilityGroup -AGName $CurrentValues.AGName -DatabaseName $params.DatabaseName -Force

# Now add it to the AAG it's meant to be in
$addParams = @{
AGName = $params.AGName
DatabaseName = $params.DatabaseName
}
if ($params.ContainsKey("FileShare")) {
$addParams.Add("FileShare", $params.FileShare)
}
Add-DatabaseToAvailabilityGroup @addParams
}
} else {
if ($Ensure -eq "Present") {
# Add to AG
Write-Verbose -Message "Adding $DatabaseName from $AGName"
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]

$cmdParams = @{
AGName = $params.AGName
DatabaseName = $params.DatabaseName
}
if ($params.ContainsKey("FileShare")) {
$cmdParams.Add("FileShare", $params.FileShare)
}
Add-DatabaseToAvailabilityGroup @cmdParams
}
} else {
# Remove from the AG
Write-Verbose -Message "Removing $DatabaseName from $AGName"
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]
Remove-DatabaseFromAvailabilityGroup -AGName $params.AGName -DatabaseName $params.DatabaseName -Force
}
}
}
}

function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)] [System.String] $DatabaseName,
[parameter(Mandatory = $true)] [System.String] $AGName,
[parameter(Mandatory = $false)] [System.String] $FileShare,
[parameter(Mandatory = $true)] [ValidateSet("Present","Absent")] [System.String] $Ensure,
[parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
)

$CurrentValues = Get-TargetResource @PSBoundParameters

Write-Verbose -Message "Checking AAG configuration for $DatabaseName"

return Test-xSharePointSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("Ensure", "AGName")
}

Loading

0 comments on commit 50d7769

Please sign in to comment.