Add shared functions to module_utils/powershell.ps1 and refactor powershell modules to utilize the common powershell code
This commit is contained in:
parent
3b5c568b10
commit
4268cb6a2d
10 changed files with 47 additions and 137 deletions
|
@ -1,13 +1,11 @@
|
||||||
#!powershell
|
#!powershell
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
If ($args.Length -gt 0)
|
$params = Parse-Args $args;
|
||||||
{
|
|
||||||
$params = Get-Content $args[0] | ConvertFrom-Json;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = 'FIXME';
|
$data = 'FIXME';
|
||||||
|
|
||||||
$result = New-Object psobject;
|
$result = New-Object psobject;
|
||||||
$result | Add-Member -MemberType NoteProperty -Name fixme -Value $data;
|
Set-Attr $result "fixme" $data;
|
||||||
echo $result | ConvertTo-Json;
|
echo $result | ConvertTo-Json;
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#!powershell
|
#!powershell
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
If ($args.Length -gt 0)
|
$params = Parse-Args $args;
|
||||||
{
|
|
||||||
$params = Get-Content $args[0] | ConvertFrom-Json;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = 'FIXME';
|
$data = 'FIXME';
|
||||||
|
|
||||||
$result = New-Object psobject;
|
$result = New-Object psobject;
|
||||||
$result | Add-Member -MemberType NoteProperty -Name fixme -Value $data;
|
Set-Attr $result "fixme" $data;
|
||||||
echo $result | ConvertTo-Json;
|
echo $result | ConvertTo-Json;
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#!powershell
|
#!powershell
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
If ($args.Length -gt 0)
|
$params = Parse-Args $args;
|
||||||
{
|
|
||||||
$params = Get-Content $args[0] | ConvertFrom-Json;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = 'FIXME';
|
$data = 'FIXME';
|
||||||
|
|
||||||
$result = New-Object psobject;
|
$result = New-Object psobject;
|
||||||
$result | Add-Member -MemberType NoteProperty -Name fixme -Value $data;
|
Set-Attr $result "fixme" $data;
|
||||||
echo $result | ConvertTo-Json;
|
echo $result | ConvertTo-Json;
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#!powershell
|
#!powershell
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
If ($args.Length -gt 0)
|
$params = Parse-Args $args;
|
||||||
{
|
|
||||||
$params = Get-Content $args[0] | ConvertFrom-Json;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = 'FIXME';
|
$data = 'FIXME';
|
||||||
|
|
||||||
$result = New-Object psobject;
|
$result = New-Object psobject;
|
||||||
$result | Add-Member -MemberType NoteProperty -Name fixme -Value $data;
|
Set-Attr $result "fixme" $data;
|
||||||
echo $result | ConvertTo-Json;
|
echo $result | ConvertTo-Json;
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#!powershell
|
#!powershell
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
If ($args.Length -gt 0)
|
$params = Parse-Args $args;
|
||||||
{
|
|
||||||
$params = Get-Content $args[0] | ConvertFrom-Json;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = 'FIXME';
|
$data = 'FIXME';
|
||||||
|
|
||||||
$result = New-Object psobject;
|
$result = New-Object psobject;
|
||||||
$result | Add-Member -MemberType NoteProperty -Name fixme -Value $data;
|
Set-Attr $result "fixme" $data;
|
||||||
echo $result | ConvertTo-Json;
|
echo $result | ConvertTo-Json;
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
#!powershell
|
#!powershell
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
If ($args.Length -gt 0)
|
$params = Parse-Args $args;
|
||||||
{
|
|
||||||
$params = Get-Content $args[0] | ConvertFrom-Json;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = 'pong';
|
$data = 'pong';
|
||||||
If ($params.data.GetType)
|
If ($params.data.GetType)
|
||||||
|
@ -13,5 +11,5 @@ If ($params.data.GetType)
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = New-Object psobject;
|
$result = New-Object psobject;
|
||||||
$result | Add-Member -MemberType NoteProperty -Name ping -Value $data;
|
Set-Attr $result "ping" $data;
|
||||||
echo $result | ConvertTo-Json;
|
echo $result | ConvertTo-Json;
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
#!powershell
|
#!powershell
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
$params = New-Object psobject;
|
$params = Parse-Args $args;
|
||||||
If ($args.Length -gt 0)
|
|
||||||
{
|
|
||||||
$params = Get-Content $args[0] | ConvertFrom-Json;
|
|
||||||
}
|
|
||||||
|
|
||||||
$src = '';
|
$src = '';
|
||||||
If ($params.src.GetType)
|
If ($params.src.GetType)
|
||||||
|
@ -28,6 +25,6 @@ $bytes = [System.IO.File]::ReadAllBytes($src);
|
||||||
$content = [System.Convert]::ToBase64String($bytes);
|
$content = [System.Convert]::ToBase64String($bytes);
|
||||||
|
|
||||||
$result = New-Object psobject;
|
$result = New-Object psobject;
|
||||||
$result | Add-Member -MemberType NoteProperty -Name content -Value $content;
|
Set-Attr $result "content" $content;
|
||||||
$result | Add-Member -MemberType NoteProperty -Name encoding -Value 'base64';
|
Set-Attr $result "encoding" "base64";
|
||||||
echo $result | ConvertTo-Json;
|
echo $result | ConvertTo-Json;
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
#!powershell
|
#!powershell
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
$params = New-Object psobject;
|
$params = Parse-Args $args;
|
||||||
If ($args.Length -gt 0)
|
|
||||||
{
|
|
||||||
$params = Get-Content $args[0] | ConvertFrom-Json;
|
|
||||||
}
|
|
||||||
|
|
||||||
$path = '';
|
$path = '';
|
||||||
If ($params.path.GetType)
|
If ($params.path.GetType)
|
||||||
|
@ -22,30 +19,30 @@ If ($params.get_md5.GetType)
|
||||||
$stat = New-Object psobject;
|
$stat = New-Object psobject;
|
||||||
If (Test-Path $path)
|
If (Test-Path $path)
|
||||||
{
|
{
|
||||||
$stat | Add-Member -MemberType NoteProperty -Name exists -Value $TRUE;
|
Set-Attr $stat "exists" $TRUE;
|
||||||
$info = Get-Item $path;
|
$info = Get-Item $path;
|
||||||
If ($info.Directory) # Only files have the .Directory attribute.
|
If ($info.Directory) # Only files have the .Directory attribute.
|
||||||
{
|
{
|
||||||
$stat | Add-Member -MemberType NoteProperty -Name isdir -Value $FALSE;
|
Set-Attr $stat "isdir" $FALSE;
|
||||||
$stat | Add-Member -MemberType NoteProperty -Name size -Value $info.Length;
|
Set-Attr $stat "size" $info.Length;
|
||||||
}
|
}
|
||||||
Else
|
Else
|
||||||
{
|
{
|
||||||
$stat | Add-Member -MemberType NoteProperty -Name isdir -Value $TRUE;
|
Set-Attr $stat "isdir" $TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Else
|
Else
|
||||||
{
|
{
|
||||||
$stat | Add-Member -MemberType NoteProperty -Name exists -Value $FALSE;
|
Set-Attr $stat "exists" $FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
If ($get_md5 -and $stat.exists -and -not $stat.isdir)
|
If ($get_md5 -and $stat.exists -and -not $stat.isdir)
|
||||||
{
|
{
|
||||||
$path_md5 = (Get-FileHash -Path $path -Algorithm MD5).Hash.ToLower();
|
$path_md5 = (Get-FileHash -Path $path -Algorithm MD5).Hash.ToLower();
|
||||||
$stat | Add-Member -MemberType NoteProperty -Name md5 -Value $path_md5;
|
Set-Attr $stat "md5" $path_md5;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = New-Object psobject;
|
$result = New-Object psobject;
|
||||||
$result | Add-Member -MemberType NoteProperty -Name stat -Value $stat;
|
Set-Attr $result "stat" $stat;
|
||||||
$result | Add-Member -MemberType NoteProperty -Name changed -Value $FALSE;
|
Set-Attr $result "changed" $FALSE;
|
||||||
echo $result | ConvertTo-Json;
|
echo $result | ConvertTo-Json;
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
#!powershell
|
|
||||||
# WANT_JSON
|
|
||||||
|
|
||||||
If ($args.Length -gt 0)
|
|
||||||
{
|
|
||||||
$params = Get-Content $args[0] | ConvertFrom-Json;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = 'pong';
|
|
||||||
If ($params.data.GetType)
|
|
||||||
{
|
|
||||||
$data = $params.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = New-Object psobject;
|
|
||||||
$result | Add-Member -MemberType NoteProperty -Name ping -Value $data;
|
|
||||||
echo $result | ConvertTo-Json;
|
|
||||||
|
|
||||||
# _______ _ _
|
|
||||||
# |__ __| | (_)
|
|
||||||
# | | | |__ _ ___
|
|
||||||
# | | | '_ \| / __|
|
|
||||||
# | | | | | | \__ \
|
|
||||||
# __|_| |_| |_|_|___/
|
|
||||||
# |_ _|
|
|
||||||
# | | ___
|
|
||||||
# | | / __|
|
|
||||||
# _| |_\__ \
|
|
||||||
# |___/\|___/
|
|
||||||
# / \
|
|
||||||
# / /\ \
|
|
||||||
# / ____ \
|
|
||||||
# /_/ \_\
|
|
||||||
# | |
|
|
||||||
# | | __ _ _ __ __ _ ___
|
|
||||||
# | | / _` | '__/ _` |/ _ \
|
|
||||||
# | |___| (_| | | | (_| | __/
|
|
||||||
# |______\__,_|_| \__, |\___|
|
|
||||||
# __/ |
|
|
||||||
# ____ _ |___/
|
|
||||||
# | _ \| | | |
|
|
||||||
# | |_) | | ___ ___| | __
|
|
||||||
# | _ <| |/ _ \ / __| |/ /
|
|
||||||
# | |_) | | (_) | (__| <
|
|
||||||
# |____/|_|\___/ \___|_|\_\
|
|
||||||
# / __ \ / _|
|
|
||||||
# | | | | |_
|
|
||||||
# | | | | _|
|
|
||||||
# | |__| | |
|
|
||||||
# \____/|_| __ __
|
|
||||||
# / ____| | / _|/ _|
|
|
||||||
# | (___ | |_ _ _| |_| |_
|
|
||||||
# \___ \| __| | | | _| _|
|
|
||||||
# ____) | |_| |_| | | | |
|
|
||||||
# |_____/ \__|\__,_|_| |_|
|
|
||||||
# | | | |
|
|
||||||
# | |_ _ ___| |_
|
|
||||||
# _ | | | | / __| __|
|
|
||||||
# | |__| | |_| \__ \ |_
|
|
||||||
# \____/_\__,_|___/\__|
|
|
||||||
# |__ __|
|
|
||||||
# | | ___
|
|
||||||
# | |/ _ \
|
|
||||||
# | | (_) |
|
|
||||||
# __|_|\___/ _
|
|
||||||
# | \/ | | |
|
|
||||||
# | \ / | __ _| | _____
|
|
||||||
# | |\/| |/ _` | |/ / _ \
|
|
||||||
# | | | | (_| | < __/
|
|
||||||
# |_|__|_|\__,_|_|\_\___|
|
|
||||||
# |__ __| |
|
|
||||||
# | | | |__ ___
|
|
||||||
# | | | '_ \ / _ \
|
|
||||||
# | | | | | | __/
|
|
||||||
# __|_|_ |_| |_|\___|
|
|
||||||
# | ____(_) |
|
|
||||||
# | |__ _| | ___
|
|
||||||
# | __| | | |/ _ \
|
|
||||||
# | | | | | __/
|
|
||||||
# |_|__ |_|_|\___|
|
|
||||||
# | _ \(_)
|
|
||||||
# | |_) |_ __ _ __ _ ___ _ __
|
|
||||||
# | _ <| |/ _` |/ _` |/ _ \ '__|
|
|
||||||
# | |_) | | (_| | (_| | __/ |
|
|
||||||
# |____/|_|\__, |\__, |\___|_|
|
|
||||||
# __/ | __/ |
|
|
||||||
# |___/ |___/
|
|
15
windows/win_ping.ps1
Normal file
15
windows/win_ping.ps1
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#!powershell
|
||||||
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
|
$params = Parse-Args $args;
|
||||||
|
|
||||||
|
$data = 'pong';
|
||||||
|
If ($params.data.GetType)
|
||||||
|
{
|
||||||
|
$data = $params.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = New-Object psobject;
|
||||||
|
Set-Attr $result "ping" $data;
|
||||||
|
echo $result | ConvertTo-Json;
|
Loading…
Reference in a new issue