Public/New-Location.ps1
|
<#
.SYNOPSIS Creates a new location. .DESCRIPTION Creates a new location. If the result returns null, try the parameter "-Verbose" to get more details. .EXAMPLE .LINK https://github.com/erwindevreugd/PSDataConduIT .EXTERNALHELP PSDataConduIT-help.xml #> function New-Location { [CmdletBinding()] param ( [Parameter( Position = 0, Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The name of the server where the DataConduIT service is running or localhost.')] [string] $Server = $Script:Server, [Parameter( Position = 1, Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The credentials used to authenticate the user to the DataConduIT service.')] [PSCredential] $Credential = $Script:Credential, [ValidateLength(1, 255)] [Parameter( Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = 'Specifies the name of the new location.')] [string] $Name, [Parameter( Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'Specifies the segment id to which to add the new location.')] [int] $SegmentID ) process { $parameters = @{ ComputerName = $Server; Namespace = $Script:OnGuardNamespace; Class = "Lnl_Location"; } if ($Credential -ne $null) { $parameters.Add("Credential", $Credential) } Set-WmiInstance @parameters -Arguments @{ Name = $Name; SegmentID = $SegmentID; } | Select-Object *, @{L = 'LocationID'; E = {$_.ID}} | Get-Location } } |