diff --git a/SnipeitPS/Private/Get-SnipeItAlias.ps1 b/SnipeitPS/Private/Get-SnipeItAlias.ps1 new file mode 100644 index 0000000..08218d6 --- /dev/null +++ b/SnipeitPS/Private/Get-SnipeItAlias.ps1 @@ -0,0 +1,38 @@ + Function Get-SnipeItAlias(){ + @{'Get-Asset' = 'Get-SnipeItAsset'; + 'Get-AssetMaintenance' = 'Get-SnipeItAssetMaintenance'; + 'Get-Category' = 'Get-SnipeItCategory'; + 'Get-Company' = 'Get-SnipeItCompany'; + 'Get-Component' = 'Get-SnipeItCompany'; + 'Get-CustomField' = 'Get-SnipeItCustomField'; + 'Get-Department' = 'Get-SnipeItDepartment'; + 'Get-Fieldset' = 'Get-SnipeItFieldset'; + 'Get-Manufacturer' = 'Get-SnipeItManufacturer'; + 'Get-Model' = 'Get-SnipeItModel'; + 'Get-Status' = 'Get-SnipeItStatus'; + 'Get-Supplier' = 'Get-SnipeItSupplier'; + 'Get-User' = 'Get-SnipeItUser'; + 'New-Asset' = 'New-SnipeItAsset'; + 'New-AssetMaintenance' = 'New-SnipeItAssetMaintenance'; + 'New-Category' = 'New-SnipeItCategory'; + 'New-Component' = 'New-SnipeItComponent'; + 'New-CustomField' = 'New-SnipeItCustomField'; + 'New-Department' = 'New-SnipeItDepartment'; + 'New-License' = 'New-SnipeItLicense'; + 'Set-License' = 'Set-SnipeItLicense'; + 'New-Location' = 'New-SnipeItLocation'; + 'New-Manufacturer' = 'New-SnipeItManufacturer'; + 'New-Model' = 'New-SnipeItModel'; + 'New-User' = 'New-SnipeItUser'; + 'Set-Asset' = 'Set-SnipeItAsset'; + 'Set-AssetOwner' = 'Set-SnipeItAssetOwner'; + 'Set-Component' = 'Set-SnipeItComponent'; + 'Set-Model' = 'Set-SnipeItModel'; + 'Set-Info' = 'Set-SnipeItInfo'; + 'Set-User' = 'Set-SnipeItUser'; + 'New-Accessory' = 'New-SnipeItAccessory'; + 'Set-Accessory' = 'Set-SnipeItAccessory'; + 'Get-Accessory' = 'Get-SnipeItAccessory'; + 'Remove-Asset' = 'Remove-SnipeItAsset'; + 'Remove-User' = 'Remove-SnipeItUser';} +} diff --git a/SnipeitPS/Private/Set-SnipeItAlias.ps1 b/SnipeitPS/Private/Set-SnipeItAlias.ps1 index 26cc63d..899f316 100644 --- a/SnipeitPS/Private/Set-SnipeItAlias.ps1 +++ b/SnipeitPS/Private/Set-SnipeItAlias.ps1 @@ -6,46 +6,11 @@ function Set-SnipeItAlias() )] param() Write-Verbose "Setting compatibility aliases.. " - $aliases= @{'Get-Asset' = 'Get-SnipeItAsset'; - 'Get-AssetMaintenance' = 'Get-SnipeItAssetMaintenance'; - 'Get-Category' = 'Get-SnipeItCategory'; - 'Get-Company' = 'Get-SnipeItCompany'; - 'Get-Component' = 'Get-SnipeItCompany'; - 'Get-CustomField' = 'Get-SnipeItCustomField'; - 'Get-Department' = 'Get-SnipeItDepartment'; - 'Get-Fieldset' = 'Get-SnipeItFieldset'; - 'Get-Manufacturer' = 'Get-SnipeItManufacturer'; - 'Get-Model' = 'Get-SnipeItModel'; - 'Get-Status' = 'Get-SnipeItStatus'; - 'Get-Supplier' = 'Get-SnipeItSupplier'; - 'Get-User' = 'Get-SnipeItUser'; - 'New-Asset' = 'New-SnipeItAsset'; - 'New-AssetMaintenance' = 'New-SnipeItAssetMaintenance'; - 'New-Category' = 'New-SnipeItCategory'; - 'New-Component' = 'New-SnipeItComponent'; - 'New-CustomField' = 'New-SnipeItCustomField'; - 'New-Department' = 'New-SnipeItDepartment'; - 'New-License' = 'New-SnipeItLicense'; - 'Set-License' = 'Set-SnipeItLicense'; - 'New-Location' = 'New-SnipeItLocation'; - 'New-Manufacturer' = 'New-SnipeItManufacturer'; - 'New-Model' = 'New-SnipeItModel'; - 'New-User' = 'New-SnipeItUser'; - 'Set-Asset' = 'Set-SnipeItAsset'; - 'Set-AssetOwner' = 'Set-SnipeItAssetOwner'; - 'Set-Component' = 'Set-SnipeItComponent'; - 'Set-Model' = 'Set-SnipeItModel'; - 'Set-Info' = 'Set-SnipeItInfo'; - 'Set-User' = 'Set-SnipeItUser'; - 'New-Accessory' = 'New-SnipeItAccessory'; - 'Set-Accessory' = 'Set-SnipeItAccessory'; - 'Get-Accessory' = 'Get-SnipeItAccessory'; - 'Remove-Asset' = 'Remove-SnipeItAsset'; - 'Remove-User' = 'Remove-SnipeItUser';} Write-Verbose "All aliases are deprediated." - ForEach ($key in $aliases.Keys ) { - New-Alias -Name $key -Value $($aliases[$key]) -Scope 1 - Write-Verbose ("{0,5} -> {1}" -f $key,$($aliases[$key])) + $SnipeItAliases = get-SnipeItAlias + ForEach ($key in $SnipeItAliases.Keys ) { + New-Alias -Name $key -Value $($SnipeItAliases[$key]) -Scope 1 + Write-Verbose ("{0,5} -> {1}" -f $key,$($SnipeItAliases[$key])) } Write-Verbose "Please start using native 'SnipeIt' prfixed functions instead." Get-Command -Module SnipeItPS -CommandType Alias | Select-Object -Property DisplayName,ResolvedCommand diff --git a/SnipeitPS/Private/Test-SnipeItAlias.ps1 b/SnipeitPS/Private/Test-SnipeItAlias.ps1 index 2aee0f4..0664cb7 100644 --- a/SnipeitPS/Private/Test-SnipeItAlias.ps1 +++ b/SnipeitPS/Private/Test-SnipeItAlias.ps1 @@ -9,5 +9,7 @@ function Test-SnipeItAlias() ) if($invocationName -ne $commandName) { Write-Warning "$invocationName is still working, but it has been superceded by $commandName, please use it instead." + Write-Warning 'To update your scripts you can use Update-SnipeItAlias helper function: ' + Write-Warning '"Get-Content [your-script.ps1] | Update-SnipeItAlias | Out-File [new-script-name.ps1]"' } } diff --git a/SnipeitPS/Public/Update-SnipeItAlias.ps1 b/SnipeitPS/Public/Update-SnipeItAlias.ps1 new file mode 100644 index 0000000..865f7da --- /dev/null +++ b/SnipeitPS/Public/Update-SnipeItAlias.ps1 @@ -0,0 +1,54 @@ +<# +.SYNOPSIS +Replaces old SnipeItPS commands with new ones + +.DESCRIPTION +Replaces old SnipeItPS commands with new ones + +.PARAMETER String +Input string + +.EXAMPLE +Get-Content [your-script.ps1] | Update-SnipeItAlias | Out-File [new-script-name.ps1] +Replaces old command from file "your-script.ps1" and creates new script "new-script-name.ps1" +After testing new file you can replace old file with new. + +#> + + +function Update-SnipeItAlias() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + param( + [Parameter(Mandatory = $true, + ValueFromPipeline = $true)] + [string[]] + $String + ) + begin{ + Write-Verbose "Replacing old SnipeIt fuctions with new ones.. " + $SnipeItAliases = Get-SnipeItAlias + + } + process { + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + ForEach ($st in $String){ + $result = $st + ForEach ($key in $SnipeItAliases.Keys ) { + #Write-Verbose "Replacing $key with $($SnipeItAliases[$key])" + $result = $result -replace $key, $SnipeItAliases[$key] + } + $result + } + } + } + end{ + Write-Verbose "..replacing done" + } + + + +} diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index fa1464e..0a7186b 100644 --- a/SnipeitPS/SnipeItPS.psd1 +++ b/SnipeitPS/SnipeItPS.psd1 @@ -110,7 +110,9 @@ FunctionsToExport = @( 'Set-SnipeItAccessory', 'Get-SnipeItAccessory', 'Remove-SnipeItAsset', - 'Remove-SnipeItUser' + 'Remove-SnipeItUser', + 'Update-SnipeItAlias' + ) # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. diff --git a/SnipeitPS/SnipeItPS.psm1 b/SnipeitPS/SnipeItPS.psm1 index 783e814..e85ba63 100644 --- a/SnipeitPS/SnipeItPS.psm1 +++ b/SnipeitPS/SnipeItPS.psm1 @@ -14,5 +14,43 @@ Get-ChildItem $scriptRoot *.ps1 | ForEach-Object { Import-Module $_.FullName } + +$SnipeItAliases= @{'Get-Asset' = 'Get-SnipeItAsset'; + 'Get-AssetMaintenance' = 'Get-SnipeItAssetMaintenance'; + 'Get-Category' = 'Get-SnipeItCategory'; + 'Get-Company' = 'Get-SnipeItCompany'; + 'Get-Component' = 'Get-SnipeItCompany'; + 'Get-CustomField' = 'Get-SnipeItCustomField'; + 'Get-Department' = 'Get-SnipeItDepartment'; + 'Get-Fieldset' = 'Get-SnipeItFieldset'; + 'Get-Manufacturer' = 'Get-SnipeItManufacturer'; + 'Get-Model' = 'Get-SnipeItModel'; + 'Get-Status' = 'Get-SnipeItStatus'; + 'Get-Supplier' = 'Get-SnipeItSupplier'; + 'Get-User' = 'Get-SnipeItUser'; + 'New-Asset' = 'New-SnipeItAsset'; + 'New-AssetMaintenance' = 'New-SnipeItAssetMaintenance'; + 'New-Category' = 'New-SnipeItCategory'; + 'New-Component' = 'New-SnipeItComponent'; + 'New-CustomField' = 'New-SnipeItCustomField'; + 'New-Department' = 'New-SnipeItDepartment'; + 'New-License' = 'New-SnipeItLicense'; + 'Set-License' = 'Set-SnipeItLicense'; + 'New-Location' = 'New-SnipeItLocation'; + 'New-Manufacturer' = 'New-SnipeItManufacturer'; + 'New-Model' = 'New-SnipeItModel'; + 'New-User' = 'New-SnipeItUser'; + 'Set-Asset' = 'Set-SnipeItAsset'; + 'Set-AssetOwner' = 'Set-SnipeItAssetOwner'; + 'Set-Component' = 'Set-SnipeItComponent'; + 'Set-Model' = 'Set-SnipeItModel'; + 'Set-Info' = 'Set-SnipeItInfo'; + 'Set-User' = 'Set-SnipeItUser'; + 'New-Accessory' = 'New-SnipeItAccessory'; + 'Set-Accessory' = 'Set-SnipeItAccessory'; + 'Get-Accessory' = 'Get-SnipeItAccessory'; + 'Remove-Asset' = 'Remove-SnipeItAsset'; + 'Remove-User' = 'Remove-SnipeItUser';} + #Create unprefixed aliases Set-SnipeItAlias diff --git a/docs/SnipeItPS.md b/docs/SnipeItPS.md index 2189f2f..4b03e7d 100644 --- a/docs/SnipeItPS.md +++ b/docs/SnipeItPS.md @@ -122,3 +122,6 @@ Updates Model on Snipe-it asset system ### [Set-SnipeItUser](Set-SnipeItUser.md) Creates a new user +### [Update-SnipeItAlias](Update-SnipeItAlias.md) +{{ Fill in the Synopsis }} + diff --git a/docs/Update-SnipeItAlias.md b/docs/Update-SnipeItAlias.md new file mode 100644 index 0000000..607bdd4 --- /dev/null +++ b/docs/Update-SnipeItAlias.md @@ -0,0 +1,91 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeitPS +online version: +schema: 2.0.0 +--- + +# Update-SnipeItAlias + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Update-SnipeItAlias [-String] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -String +{{ Fill String Description }} + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String[] + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS