mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-15 10:45:48 +00:00
Helper function to update existing SnipeItPS scripts
This commit is contained in:
parent
06305b1b63
commit
906fedd71a
6 changed files with 121 additions and 40 deletions
38
SnipeitPS/Private/Get-SnipeItAlias.ps1
Normal file
38
SnipeitPS/Private/Get-SnipeItAlias.ps1
Normal file
|
|
@ -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';}
|
||||||
|
}
|
||||||
|
|
@ -6,46 +6,11 @@ function Set-SnipeItAlias()
|
||||||
)]
|
)]
|
||||||
param()
|
param()
|
||||||
Write-Verbose "Setting compatibility aliases.. "
|
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."
|
Write-Verbose "All aliases are deprediated."
|
||||||
ForEach ($key in $aliases.Keys ) {
|
$SnipeItAliases = get-SnipeItAlias
|
||||||
New-Alias -Name $key -Value $($aliases[$key]) -Scope 1
|
ForEach ($key in $SnipeItAliases.Keys ) {
|
||||||
Write-Verbose ("{0,5} -> {1}" -f $key,$($aliases[$key]))
|
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."
|
Write-Verbose "Please start using native 'SnipeIt' prfixed functions instead."
|
||||||
Get-Command -Module SnipeItPS -CommandType Alias | Select-Object -Property DisplayName,ResolvedCommand
|
Get-Command -Module SnipeItPS -CommandType Alias | Select-Object -Property DisplayName,ResolvedCommand
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,7 @@ function Test-SnipeItAlias()
|
||||||
)
|
)
|
||||||
if($invocationName -ne $commandName) {
|
if($invocationName -ne $commandName) {
|
||||||
Write-Warning "$invocationName is still working, but it has been superceded by $commandName, please use it instead."
|
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]"'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
36
SnipeitPS/Public/Update-SnipeItAlias.ps1
Normal file
36
SnipeitPS/Public/Update-SnipeItAlias.ps1
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
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 1 "
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -110,7 +110,9 @@ FunctionsToExport = @(
|
||||||
'Set-SnipeItAccessory',
|
'Set-SnipeItAccessory',
|
||||||
'Get-SnipeItAccessory',
|
'Get-SnipeItAccessory',
|
||||||
'Remove-SnipeItAsset',
|
'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.
|
# 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.
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,43 @@ Get-ChildItem $scriptRoot *.ps1 | ForEach-Object {
|
||||||
Import-Module $_.FullName
|
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
|
#Create unprefixed aliases
|
||||||
Set-SnipeItAlias
|
Set-SnipeItAlias
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue