Powershell Script Send-zip not working when running in cmd

I found there is powershell send-zip script available in technet.  I tested it and found that it works when the script is running under powershell env, but when it is calling in cmd env, I can see the zip file, but there is nothing in it.  If
I add the "-noexit" switch it runs normally.  Anyone have ideas what might be happening?
The orig codes is as following:
function global:SEND-ZIP ($zipfilename, $filename) { 
# The $zipHeader variable contains all the data that needs to sit on the top of the 
# Binary file for a standard .ZIP file
$zipHeader=[char]80 + [char]75 + [char]5 + [char]6 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0 + [char]0
# Check to see if the Zip file exists, if not create a blank one
If ( (TEST-PATH $zipfilename) -eq $FALSE ) { Add-Content $zipfilename -value $zipHeader }
# Create an instance to Windows Explorer's Shell comObject
$ExplorerShell=NEW-OBJECT -comobject 'Shell.Application'
# Send whatever file / Folder is specified in $filename to the Zipped folder $zipfilename
$SendToZip=$ExplorerShell.Namespace($zipfilename.tostring()).CopyHere($filename.ToString())
SEND-ZIP C:\abc\a.ZIP C:\a\a.bak

I've had the same problem with similar code found on another web site.
The reason the zip file ends up being empty is that the temporary $ExplorerShell object you created is deleted when the send-zip function returns,
and any incomplete copy operation that may still be ongoing at that time is aborted. (The copy operation is asynchronous, and continues after the CopyHere() function returns.)
To work around this, you need to add a delay loop before you return, waiting for the copied object to appear in the zip.
(Note that adding a fixed delay, like I've seen on other web sites, does not work: Small files appear almost immediately, whereas large file or worse still large subdirectory trees can take a long time to appear.)
Try changing the end of your routine to something like...
# Create an instance to Windows Explorer's Shell comObject 
$ExplorerShell=NEW-OBJECT -comobject 'Shell.Application' 
# Open the zip file object
$zipFile = $ExplorerShell.Namespace($zipfilename.tostring())
# Count how many objects were in the zip file initially
$count = $zipFile.Items().Count
# Send whatever file / Folder is specified in $filename to the Zipped folder $zipfilename 
$SendToZip=$zipFile.CopyHere($filename.ToString())
# Wait until the file / folder appears in the zip file
$count += 1 # We expect one more object to be there eventually
while ($zipFile.Items().Count -lt $count) {
    Write-Debug "$filename not in the zip file yet. Sleeping 100ms"
    Start-Sleep -milliseconds 100
# Return deletes the $zipFile object, and aborts incomplete copy operations.

Similar Messages

  • Multitouch on track pad not working when running Windows 8 in boot camp

    Does anyone know a work around on how to resolve the issue of more than one fingers on the trackpad? For example, I use one finger to click a window then another finger to slide/move the window to a different location on the screen. This does not work when running Windows 8 in Boot Camp latest version. Any suggestion is much appreciated.

    very very few gestures are supported in windows
    https://discussions.apple.com/message/24548533#24548533
    if it's a limitation from ms you need to contact them
    if it's a limitation from apples drivers you can use feedback channel
    http://www.apple.com/feedback/

  • Hyperlink is not working when running on sun solaris OS

    Hi,
    I have Created PDF file using oracle reports 2.5 version and included hyperlinks in reports which will open files located on our intranet server(http://cup2.ngc.co.uk). Hyperlinks are working properly when I generated report on window xp machine but not working when I compiled and executed report on solaris unix server(reports 6i).
    please let me know why hyperlinks is not working when executed on solaris((5.8). do we need any setup to work hyperlinks on unix server.
    Thanks in advance,

    Ok, there are 2 docs i've tried.
    A = Doc created originally from MPB Pages with hyperlink
    B = Doc created from iPad Pages with hyperlink
    A was transfered to iPad Pages using iTune. I emailed A as pdf from iPad to gmail and reopen the file on iPad using Quickoffice / PDF Reader Lite, the link is NOT active, not working. BUT, when i read A using MBP gmail, the link is ACTIVE, i click on the link and it brings me to the correct webpage.
    As for B, after the page was created with links on iPad, i emailed B as pdf from iPad to gmail, reopen the file on iPad using Quickoffice / PDF Reader Lite, the link is NOT active, and this time, when i read B using MBP gmail, the link is NOT active as well.
    Weird huh? I'm starting to sense that is the problem with iPad Pages. What say you?

  • Why does this script not work when run with osascript cli?

    I wrote the following to interface with geektool to display a list of todo's on my desktop (i'm sure it's been done elsewhere, but I wanted to try it myself). I had it working fine until I tried ordering the output to place the highest priority items at the top of the list. The following code works properly during development in Script Editor, but when geektool launches the command using osascript ~/Library/Scripts/todos.scpt it only displays the initial "TODOS:" without displaying the rest of the info. Searching the Applescript Release notes, I found that some versions of Applescript 1.8 had issues with null characters when using the osascript cli, however, I'm running 1.10.7 so it shouldn't be an issue (and I'm not sure how to check for null characters in Applescript even if it were). Anybody have any ideas on what's going on here?
    set output to {"TODOS:
    set highpri to {}
    set medium to {}
    set low to {}
    set nada to {}
    tell application "iCal"
    repeat with i in calendars
    repeat with j in todos of i
    if (completion date of j as string) is equal to "" then
    if priority of j as string is equal to "high priority" then
    copy summary of j & "
    " to end of highpri
    end if
    if priority of j as string is equal to "medium priority" then
    copy summary of j & "
    " to end of medium
    end if
    if priority of j as string is equal to "low priority" then
    copy summary of j & "
    " to end of low
    end if
    if priority of j as string is equal to "no priority" then
    copy summary of j & "
    " to end of nada
    end if
    end if
    end repeat
    end repeat
    end tell
    return (output & highpri & medium & low & nada) as string

    well, i'd been pulling my hair out for quite a while with this and decided it was time to ask for help, but I thought I'd give it one last shot and found a resolution almost immediately. I figured that problem had to be caused by the way applescript was concatenating the lists, so I got rid of the lists completely and it still wouldn't work. This convinced me that it must be newline related since that was the only special character left in the string. I opened up the script in vi, but the default compiled script format is not human readable. The osascript man page indicated that it would accept both compiled and text scripts, so I gave it a try, and osascript handled the raw text file wonderfully.

  • Powershell Syntax working when run in cmd, but when run through SCCM2007 Task Sequence it claims the syntax is incorrect?

    The code below is a simple powershell statement which enables me to change the execution policy so that I can run powershell scripts. When I run this in a normal windows enviroment the statement will work fine, not giving me an issue whatsoever. However,
    whenever it runs in the task sequence the TS fails. I am running this via the command line option in the task sequence, each time running this step as 3 different types of administrators.
    powershell.exe -noninteractive Set-ExecutionPolicy -ExecutionPolicy unrestricted
    Checking the log file it states this:
    Set-ExecutionPolicy : The term 'Set-ExecutionPolicy' is not recognized as the InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    name of a cmdlet, function, script file, or operable program. Check the InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    spelling of the name, or if a path was included, verify that the path is InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    correct and try again. InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    At line:1 char:1 InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    + Set-ExecutionPolicy -ExecutionPolicy unrestricted InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    + ~~~~~~~~~~~~~~~~~~~ InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    + CategoryInfo : ObjectNotFound: (Set-ExecutionPolicy:String) [], InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    CommandNotFoundException InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    + FullyQualifiedErrorId : CommandNotFoundException InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    InstallSoftware 13/10/2014 17:28:09 3768 (0x0EB8)
    Failed to run the action: Script Exception.
    Incorrect function. (Error: 00000001; Source: Windows) TSManager 13/10/2014 17:28:09 2716 (0x0A9C)
    I am new to both SCCM and Powershell, but from my point of view, this should work, considering that the syntax is not actually incorrect? Please could anyone with any idea drop some hints and tips on how to
    stop this issue.

    I'm not using 3 admin accounts at once if that's how it sounded. I have tried 3 different Admin accounts because I felt that perhaps the difference in permissions may have made a difference in whether I was able to run the syntax and scripts. So I tried
    using my own personal administrator account, the SCCMNA account, and the local admin account, which I read worked.
    At this point in the task sequence I have:
    - Installed the OS
    - Connected to the domain
    - Installed Applications such as; Flash, Shockware, Reader etc.
    Once it has installed the last application within a folder called "Helper Apps" (Which contains various Java and Adobe apps which install fine) it will then run a "Use Toolkit Package" using the MDT toolkit, once this stage is complete
    it then progresses to the Script Exception section of the TS.
    powershell.exe -noninteractive Set-ExecutionPolicy -ExecutionPolicy unrestricted
    I obviously need this to work otherwise I am not allowed to run the script, but because this syntax is "incorrect" it stops the task sequence.
    I hope this information might shed some more light on the situation.

  • Sorting array not working when run as a job

    I have a Powershell script that reads data from a log file, extracts a username and adds it to an array. I then sort the array to remove duplicates and export the data to a CSV file. The script works fine when run locally on the server but I need to call
    the script remotely for a number of servers and when I do this it does not output anything to the CSV. The script is run as a job.
    $ArrList = [System.Collections.ArrayList]@()
    # open file and read data
    $arrlist.Add("$final")
    $arrlist | sort -unique | out-file c:\scripts\iis_users.csv
    If I change the script to use add-content it can add entries to the same CSV file. But ideally I need to sort the output as there are many duplicates.

    Not sure why but that would only export the last user. I didn't have time to investigate so instead I decided to only add users to the array after first checking they didn't exist already:
    if ($arrlist -notcontains $final)
    $arrlist.Add("$final")
    add-content c:\scripts\iis_users.csv "$final"
    I thought this would create a performance hit but it seems almost as fast.

  • Send button not working when text message

    When I was texting message with my friends, all of sudden I can't type the respond message unless I have to quit and try to text my friend again. The problem is the box where you typed your message is gray out and "Send" button is inactive or gray out. This problem occurs when I upgraded my iphone 4s to iOS 6.1
    Please help.

    After Update today, SEND button no longer activates keyboard. I tapped message window area and that activated the keyboard. SEND button worked to send message. (Not sure how to describe that "message window area", but its the area where your message shows as you type.)

  • [SOLVED] Pacman and yaourt not working when run with "sudo"

    Hi,
    I am an Arch newbie, just installed Arch 3.10 on my machine. I access internet through a proxy server and I'm facing this strange problem -
    Pacman is unable to fetch packages when I run it through sudo - "sudo pacman -S smplayer" (It gives network unreachable error).
    However when I run it through root, it retrieves those same packages successfully.
    yaourt also faces a similar kind of problem -
    When I run it through sudo or as root, it is unable to retrieve packages which can be downloaded by pacman. But, when I run pacman to download those same packages, it is able to do so.
    I am using gnome 3.8, and use radiotray ( It's for listening online radios ). When I run it via 'Alt-F2' or as a startup application, it's not able to connect to any radio station ( which means it's not connecting to the internet ). However, on running it via terminal, it connects to the internet successfully. Are these 2 problems related ? I'm facing the first one even without loading gnome, so it's not gnome's problem, i guess.
    I can ping successfully through my administrator as well as root account, connect to the internet via browser, and ssh, git, bzr are also working fine.
    What can I do to resolve this ?
    Thanks
    Last edited by parinporecha (2013-09-12 06:01:06)

    parinporecha wrote:
    To configure proxy, I added the line "export http_proxy=PROXY_LINK" to the bashrc files of user and root.
    Regarding Arch 3.10, yes i meant the installation media from 2013.09.01 ( kernel 3.10 )
    That's why root works, but not sudo. Sudo clears the environment. See man sudo and man sudoers.

  • GUI_GET_DESKTOP_INFO is not worked when run in background

    Dear all,
    I want to retrieve the computer name using this function module. It is working fine in foreground but it returns no result when I run in background. Is there any other method to get the computer name in background? Thanks in advance.

    Problem solved using the following method:
      DATA: BEGIN OF usr_tabl OCCURS 10.
              INCLUDE STRUCTURE uinfo.
      DATA: END OF usr_tabl.
      DATA  th_opcode(1)                    TYPE x.
      data: size type i.
      CONSTANTS: opcode_list LIKE th_opcode VALUE 2.
      CALL 'ThUsrInfo' ID 'OPCODE' FIELD opcode_list
        ID 'TAB' FIELD usr_tabl-sys.
      describe table usr_tabl lines size.
      read table usr_tabl index size.
      write usr_tabl-term.
    while usr_tabl-term is the computer name. It works in background as well.
    Edited by: Chiew Ngee Ho on Mar 12, 2009 9:36 AM

  • Satellite L450D-11H - WLan not working when running on battery

    Hi everyone,
    I have a Satellite L450D-11H laptop running Windows 7 OS.
    When my laptop is plugged into the mains my wireless connection works fine.
    But when I unplug it and just run it using the battery, my wireless connection stops working.
    I have looked at the power settings and changed the battery option to "Maximum performance when wireless"
    But I still have the same problem. Could this be a driver issue?
    Any ideas?
    Thanks.

    [ShopOfGHD.com]Free Shipping on GHD Hair Straighteners and UGG Boots
    GHD Limited Edition Rare Only £77.01 + Free Shipping
    GHD LImited Edition Radiance Set Only £71.77 + Free Shipping
    GHD Kiss MK4 Pink Only £67.50 + Free Shipping
    GHD IV Styler Purple £84.63 + Free Shipping
    GHD Hair Straightener MK4 Pink Only £69.00 + Free Shipping
    GHD IV MK4 Dark Hair Straightener Flat Only £66.53 + Free Shipping
    GHD Ceramic Hair Straightener (MK4) Black Only £65.84 + Free Shipping
    GHD IV MK4 Gold Hair Straightener Flat Only £64.60 + Free Shipping
    GHD IV MK4 Pure Hair Straightener Flat Only £66.53 + Free Shipping
    GHD Limited Edition Hair Straightener Kit Black Only £64.69 + Free Shipping
    Discount UGG Boots 50% Off + Free Shipping
    ShopOfGHD.com specializes in selling ghd hair straighteners and ugg boots, ghd hair straightener, ghd straightener, ghd straighteners, discount ghd hair straighteners, discount ghd hair straightener.
    Website: http://www.shopofghd.com

  • FUNCTION IS NOT WORKING WHEN RUN IN SRW.RUN_REPORT, URGENT

    Hi,
    I have a report. it has got 1 Query and 2 groups.
    Q1
    |
    |
    __G1__
    |F1 |
    |F2 |
    |F3 |
    |
    |
    |
    __G2__
    |Items|
    |Sales|
    | Qty|
    |Store|
    |Func4|
    |Func5|
    |Func6|
    The Query looks like above. Now In the report I have a 3 User parameters . For Each record in G2 the functions Func4,Func5 and Func6 adds the value to the user parameters at the report level.
    Now the Func1,Func2,Func3 takes the value of last 4 record for each item at each G1 Level and devides it by 4 and prints . As an example given below
    ITEMS-----SALES-------QTY-----------STORE
    10001-----10000-------200-------------100
    10001-----20000-------500-------------200
    10001-----15000-------350-------------175
    10001-----45000-------650-------------225
    10001-----50000-------700-------------300
    AVERAGE==>32500-------550-------------225 ==> Calculated by F1,F2,F3
    20001-----70000-------900-------------400
    20001-----30000-------600-------------350
    20001-----20000-------500-------------300
    20001-----25000-------450-------------275
    20001-----35000-------550-------------225
    20001-----65000-------800-------------400
    AVERAGE==>36250-------650-------------300 ==> Avg of last 4 records
    This report takes an parameter which is part of the Where condition of the Query Q1. If I run this report from the report builder and provide the value for the parameter then the report runs fine printing the exact values. If I run the report from another report(which I have to do, due to circumstances) using SRW.Run_Report and pass the parameter in the same command. The the function FUNC4, FUNC5, FUNC6 does not do the addition, as a result the Func1,Func2,Func3 returns 0. I dont know why this is happenning .
    This is very very URGENT, My project manager is on my head to finish it ASAP. Please help.
    Thanks
    Feroz

    Hi Toby and Danny,
    Thanks for the quick reply. I dont think I am having an interdependancy of the functions. Here is an sample what two functions do at each level
    Func6 =========> This function at group level G2
    begin
    -- To initialize the user parameter for each new item.
         If :CNT = 1 Then
              :Wk4_Pos_Qty := 0;
         End If;          
    -- to add the qty value to the user parameter for last 4 records. Uchange is the no of records for each item     
    If :CNT >= :UCHANGE - 3 Then
         :Wk4_Pos_Qty := :Wk4_Pos_Qty + :Qty;
    End If;     
    return 0;
    end;
    Func3 ======> this function at group level G1
    Begin
    -- if no of records are less than 4 then devide by the no of records or devide by 4.
         If :UChange < 4 Then
                   return((:Wk4_Pos_Qty + :Qty) / :UChange);
         Else
                   return((:Wk4_Pos_Qty + :Qty)/ 4);     
         End If;     
    end;
    Here Wk4_Pos_Qty is the User parameter created to hold the calue for the Um of last 4 records Qty.
    I tried to modify the Func3 so that it looks like this
    Func3
    begin
    srw.reference(:Wk4_Pos_Qty);
         If :UChange < 4 Then
                   return((:Wk4_Pos_Qty + :Qty) / :UChange);
         Else
                   return((:Wk4_Pos_Qty + :Qty)/ 4);     
         End If;     
    end;
    But it does not effect anything. I mean its the same. The Wk4_Pos_Qty returns 0 and Func3 returns 0.
    Any Suggestions .
    Thanks
    Feroz

  • Link in Report does not work when run on Citrix

    Hello,
    we use Crystal Reports (v11) for creating Reports.
    Data is based on our CRM system "SuperOffice".
    We have several reports and what we did is to add a column that includes a link to SuperOffice.
    For example - if I have a list of contacts as a report, then every line has a link to SuperOffice.
    If I click this link, the contact in SuperOffice gets open.
    This works on lokal pc installations.
    But is doesn't work on a citrix server.
    If I click the link - nothing happens.
    Is that a known problem or does anyone have any ideas for that?
    Are there any known problems with links in reports on citrix servers?
    Thanks in advance.
    Best regards,
    Tony

    Hi Don,
    thank you for fast response.
    That is a good advice. We will check that.
    The main question is, to which folders etc. does CR needs access?
    To explain the situation better: To run the reports we use Crystal Reports Runtime (Version 11.1.1883).
    Do you (or anyone else in these forum) know where we could get information about which kinds of access CR Runtime needs to handle with these links?
    Regards,
    Tony

  • Unix script not working when executed from SAP PI communication channel

    Hi Experts,
    I am currently using the Run OS command after message processing functionality of the file adapter.
    However, the unix script doesn't seem to work when run via communication channel.
    The script runs properly when executed manually.
    The communication channel logs don't show any error as well.
    Do you have any ideas as to where the error might be.
    Thanks,
    Mike

    Hi All,
    Thank you for your replies. I appreciate this.
    @Anand, here is the script:
    #!/usr/bin/sh
    #version 1
    hostname=$(uname -a | cut -f 2 -d " ")
    MAILTO="[email protected] "
    homedir=$PWD
    echo $homedir | mailx -m -s "OB10 $hostname" $MAILTO
    /opt/java6/bin/jar -xvf OB10.zip
    ll | mailx -m -s "OB10 $hostname" $MAILTO
    What's puzzling me is that I am able to receive the email alerts.
    This means that the user has sufficient authorization to execute the script.
    But the unzip command is not working.
    I have seen the unzip work when run manually.
    Thanks,
    Mike

  • Just upgraded to Lion an am discovering that I cannot send email photos from within iPhoto. Error message says bad Internet connection or server not working, when that's not the case. Never happened in Snow Leopard! Help!!!

    Just upgraded to Lion an am discovering that I cannot send email photos from within iPhoto. Error message says bad Internet connection or server not working, when that's not the case. Never happened in Snow Leopard! Help!!!

    what email service - Yahoo mail have been acting up lately
    you can try setting Mail as your email client - it resolves this pfoblem for some people
    LN

  • The Horizontal & vertical scroll is not visible or not working when i run the form in Forms 6i.

    Hi all,
    The Horizontal & vertical scroll is not visible or not working when i run the form.
    In this form , there are 5 canvas namely
    CANVAS2 - Stacked Canvas
    PASS - Content Canvas
    MAT_RATES - Content Canvas
    DATE - Content Canvas
    PREVIOUS - Content Canvas
    I have set "Show Horizontal Scroll Bar" to "Yes" and  "Show Vertical Scroll Bar" to "Yes" in the WINDOW Property.
    I have  set "Show Horizontal Scroll Bar" to "Yes" and  "Show Vertical Scroll Bar" to "Yes" in the STACKED CANVAS Property .
    But still the Horizontal and Vertical Scroll Bar is not working when i run the Form.
    Help me with this please. How do i make it visible??
    Oracle Forms 6i..
    Thank You.

    Vijetha wrote:
    Hi all,
    The Horizontal & vertical scroll is not visible or not working when i run the form.
    I have set "Show Horizontal Scroll Bar" to "Yes" and  "Show Vertical Scroll Bar" to "Yes" in the WINDOW Property.
    I have  set "Show Horizontal Scroll Bar" to "Yes" and  "Show Vertical Scroll Bar" to "Yes" in the STACKED CANVAS Property .
    But still the Horizontal and Vertical Scroll Bar is not working when i run the Form.
    Help me with this please. How do i make it visible??
    Oracle Forms 6i..
    Thank You.
    hello vijetha,
    window and canvas show scroll bar when it need.
    You should show block property
    and set block scroll bar
    hope this helps..
    Hamid

Maybe you are looking for

  • Report that display payment terms for account receivables customers

    Hello To all, Please can you help us to find a standard report that list account receivables customers with their payment terms. Regards. Zied.

  • I have just upgraded to the new maverick system

    Everything seemed to go well but now any documents created on my Ipad (also just updated) pages, numbers and keynote will not open on my mac.  it tell me "a newer version of pages etc is availabe".  But as said this has also been updated.  I have tri

  • Adobe flash install help

    i am attempting to install a new version of adobe flash player.  During install I get the message to close "com.apple.webkit.plugin.65"  I don't know how to close this or even where to find it...installation stalls at that point.

  • Stupid airport... please help me

    Ok so my internet connection *****, ten fold. I'm so frustrated by how low and crappy it is I'm ready to throw my MacBook across the room. My roommate gets excellent internet connection and my boyfriend gets pretty good internet, and all three of us

  • Can Mac mini boot into 64-bit kernel

    http://macperformanceguide.com/SnowLeopard-64bit.html says: To determine if your Mac has 32-bit or 64-bit firmware, copy/paste the following command into Terminal: ioreg -l -p IODeviceTree | grep firmware-abi ...output: | | "firmware-abi" = <EFI64> A