summaryrefslogtreecommitdiff
path: root/windows/win_unzip.ps1
diff options
context:
space:
mode:
authorPhil Schwartz <schwartzmx@gmail.com>2014-12-30 08:42:00 -0600
committerPhil Schwartz <schwartzmx@gmail.com>2014-12-30 08:42:00 -0600
commita21e23846d20359d7d20236431e0bb662cd2a851 (patch)
tree9207164064df01ec4a52330d400396dacd8b1931 /windows/win_unzip.ps1
parent60c06b79d656597cea1f84fc78549a44a69ad562 (diff)
downloadansible-modules-extras-a21e23846d20359d7d20236431e0bb662cd2a851.tar.gz
init commit
Diffstat (limited to 'windows/win_unzip.ps1')
-rw-r--r--windows/win_unzip.ps183
1 files changed, 83 insertions, 0 deletions
diff --git a/windows/win_unzip.ps1 b/windows/win_unzip.ps1
new file mode 100644
index 00000000..de9fb73e
--- /dev/null
+++ b/windows/win_unzip.ps1
@@ -0,0 +1,83 @@
+#!powershell
+# This file is part of Ansible
+#
+# Copyright 2014, Phil Schwartz <schwartzmx@gmail.com>
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+
+# WANT_JSON
+# POWERSHELL_COMMON
+
+$params = Parse-Args $args;
+
+$result = New-Object psobject @{
+ win_unzip = New-Object psobject
+ changed = $false
+}
+
+If ($params.zip) {
+ $zip = $params.zip.toString()
+
+ If (-Not (Test-Path -path $zip)){
+ Fail-Json $result "zip file: $zip does not exist."
+ }
+}
+Else {
+ Fail-Json $result "missing required argument: zip"
+}
+
+If (-Not($params.dest -eq $null)) {
+ $dest = $params.dest.toString()
+
+ If (-Not (Test-Path $dest -PathType Container)){
+ New-Item -itemtype directory -path $dest
+ }
+}
+Else {
+ Fail-Json $result "missing required argument: dest"
+}
+
+Try {
+ cd C:\
+ $shell = New-Object -ComObject Shell.Application
+ $shell.NameSpace($dest).copyhere(($shell.NameSpace($zip)).items(), 20)
+ $result.changed = $true
+}
+Catch {
+ $sp = $zip.split(".")
+ $ext = $sp[$sp.length-1]
+
+ # Used to allow reboot after exe hotfix extraction (Windows 2008 R2 SP1)
+ # This will have no effect in most cases.
+ If (-Not ($ext -eq "exe")){
+ $result.changed = $false
+ Fail-Json $result "Error unzipping $zip to $dest"
+ }
+}
+
+If ($params.rm -eq "true"){
+ Remove-Item $zip -Recurse -Force
+ Set-Attr $result.win_unzip "rm" "true"
+}
+
+If ($params.restart -eq "true") {
+ Restart-Computer -Force
+ Set-Attr $result.win_unzip "restart" "true"
+}
+
+
+Set-Attr $result.win_unzip "zip" $zip.toString()
+Set-Attr $result.win_unzip "dest" $dest.toString()
+
+Exit-Json $result;