Unzip GZ files using Powershell

I have  Windows 2008 Server with some GZ type files in a folder. I would like to script unzipping them using Powershell, can someone tell me if this is possible and how I would do it?
The folder is d:\data_files\ and I'd like to uncompress all the .gz files in there
I've searched around on the Net but can't find much that deals with GZ files specifically. The files are all named data-1.gz, data-2.gz etc
Hello
I have  Windows 2008 Server with some GZ type files in a folder. I would like to script unzipping them using Powershell, can someone tell me if this is possible and how I would do it?
The folder is d:\data_files\ and I'd like to uncompress all the .gz files in there
I've searched around on the Net but can't find much that deals with GZ files specifically.

I also found that .Net 2.0 and above has native code for dealing with gzip files.
Function DeGZip-File{
Param(
$infile,
$outfile = ($infile -replace '\.gz$','')
$input = New-Object System.IO.FileStream $inFile, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read)
$output = New-Object System.IO.FileStream $outFile, ([IO.FileMode]::Create), ([IO.FileAccess]::Write), ([IO.FileShare]::None)
$gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress)
$buffer = New-Object byte[](1024)
while($true){
$read = $gzipstream.Read($buffer, 0, 1024)
if ($read -le 0){break}
$output.Write($buffer, 0, $read)
$gzipStream.Close()
$output.Close()
$input.Close()
$infile='C:\Temp\DECfpc1new.csv.gz'
$outfile='c:\temp\DECfpc1new.csv'
DeGZip-File $infile $outfile
You can supply the function with the full path of the file to be unzipped, and the full path of the unzipped file.
If you don't supply the unzipped file path, the function will unzip the file into the same folder as the source, and remove the .gz extension.
Inspired by Heineken.

Similar Messages

  • How to get Document Set property values in a SharePoint library in to a CSV file using Powershell

    Hi,
    How to get Document Set property values in a SharePoint library into a CSV file using Powershell?
    Any help would be greatly appreciated.
    Thank you.
    AA.

    Hi,
    According to your description, my understanding is that you want to you want to get document set property value in a SharePoint library and then export into a CSV file using PowerShell.
    I suggest you can get the document sets properties like the PowerShell Command below:
    [system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
    $siteurl="http://sp2013sps/sites/test"
    $listname="Documents"
    $mysite=new-object microsoft.sharepoint.spsite($siteurl)
    $myweb=$mysite.openweb()
    $list=$myweb.lists[$listname]
    foreach($item in $list.items)
    if($item.contenttype.name -eq "Document Set")
    if($item.folder.itemcount -eq 0)
    write-host $item.title
    Then you can use Export-Csv PowerShell Command to export to a CSV file.
    More information:
    Powershell for document sets
    How to export data to CSV in PowerShell?
    Using the Export-Csv Cmdlet
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Report the size of all SharePoint Databases in a text file using PowerShell?

    I am new to Powershell. please help me for following question with step by step process.
    How to report the size of all SharePoint Databases in a text file using PowerShell?

    Hi Paul,
    Here is the changed script, which will also include the size for the Config DB.
    Please let me know if it worked:
    #Get SharePoint Content database sizes
    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    $date = Get-Date -Format "dd-MM-yyyy"
    #Variables that you can change to fit your environment
    $TXTFile = "D:\Reports\SPContentDatabase_$date.txt"
    $SMTPServer = "yourmailserver"
    $emailFrom = "[email protected]"
    $emailTo = "[email protected]"
    $subject = "Content & Config Database size reports"
    $emailBody = "Daily/Weekly/Monthly report on Content & Config databases"
    $webapps = Get-SPWebApplication
    $configDB = Get-SPDatabase | ?{$_.Name -eq ((Get-SPFarm).Name)}
    $ConfigDBSize = [Math]::Round(($configDB.disksizerequired/1GB),2)
    Add-Content -Path $TXTFile -Value "Config Database size: $($ConfigDBSize)GB"
    Add-Content -Path $TXTFile -Value ""
    foreach($webapp in $webapps)
    $ContentDatabases = $webapp.ContentDatabases
    Add-Content -Path $TXTFile -Value "Content databases for $($webapp.url)"
    foreach($ContentDatabase in $ContentDatabases)
    $ContentDatabaseSize = [Math]::Round(($ContentDatabase.disksizerequired/1GB),2)
    Add-Content -Path $TXTFile -Value "- $($ContentDatabase.Name): $($ContentDatabaseSize)GB"
    if(!($SMTPServer) -OR !($emailFrom) -OR !($emailTo))
    Write-Host "No e-mail being sent, if you do want to send an e-mail, please enter the values for the following variables: $SMTPServer, $emailFrom and $emailTo."
    else
    Send-MailMessage -SmtpServer $SMTPServer -From $emailFrom -To $emailTo -Subject $subject -Body $emailBody -Attachment $TXTFile
    Nico Martens - MCTS, MCITP
    SharePoint 2010 Infrastructure Consultant / Trainer

  • How to get DocSet property values in a SharePoint library into a CSV file using Powershell

    Hi,
    How to get DocSet property values in a SharePoint library into a CSV file using Powershell?
    Any help would be greatly appreciated.
    Thank you.
    AA.

    Hi AOK,
    Would you please post your current script and the issue for more effcient support.
    In addition, to manage document set in sharepoint please refer to this script to start:
    ### Load SharePoint SnapIn
    2.if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
    3.{
    4. Add-PSSnapin Microsoft.SharePoint.PowerShell
    5.}
    6.### Load SharePoint Object Model
    7.[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    8.
    9.### Get web and list
    10.$web = Get-SPWeb http://myweb
    11.$list = $web.Lists["List with Document Sets"]
    12.
    13.### Get Document Set Content Type from list
    14.$cType = $list.ContentTypes["Document Set Content Type Name"]
    15.
    16.### Create Document Set Properties Hashtable
    17.[Hashtable]$docsetProperties = @{"DocumentSetDescription"="A Document Set"}
    18.$docsetProperties = @{"CustomColumn1"="Value 1"}
    19.$docsetProperties = @{"CustomColum2"="Value2"}
    20. ### Add all your Columns for your Document Set
    21.
    22.### Create new Document Set
    23.$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,"Document Set Title",$cType.Id,$docsetProperties)
    24.$web.Dispose()
    http://www.letssharepoint.com/2011/06/document-sets-und-powershell.html
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Removing non printable characters from an excel file using powershell

    Hello,
    anyone know how to remove non printable characters from an excel file using powershell?
    thanks,
    jose.

    To add - Excel is a binary file.  It cannot be managed via external methods easily.  You can write a macro that can do this.  Post in the Excel forum and explain what you are seeing and get the MVPs there to show you how to use the macro facility
    to edit cells.  Outside of cell text "unprintable" characters are a normal part of Excel.
    ¯\_(ツ)_/¯

  • How to check & unzip zip file using java

    Dear friends
    How to check & unzip zip file using java, I have some files which are pkzip or some other zip I want to find out the type of ZIp & then I want to unzip these files, pls guide me
    thanks

    How to check & unzip zip file using java, I have
    ve some files which are pkzip or some other zip I
    want to find out the type of ZIp & then I want to
    unzip these files, pls guide meWhat do you mean "other zip"? Either they're zip archives or not, there are no different types.

  • Merge xls files using powershell

    is there any way to merge xls files using powershell ?

    What does "merge" mean?  Copy cells?  Copy Sheets?  Copy formulas?  Copy Data?
    "Merge"is way too vague.
    ¯\_(ツ)_/¯

  • Is it possible to monitor State change of a .CSV file using powershell scripting ?

    Hi All,
    I just would like to know Is it possible to monitor State change of a .CSV file using powershell scripting ? We have SCOM tool which has that capability but there are some drawbacks in that for which we are not able to utilise that. So i would like
    to know is this possible using powershell.
    So if there is any number above 303 in the .CSV file then i need a email alert / notification for the same.
    Gautam.75801

    Hi Jrv,
    Thank you very much. I modified the above and it worked.
    Import-Csv C:\SCOM_Tasks\GCC2010Capacitymanagement\CapacityMgntData.csv | ?{$_.Mailboxes -gt 303} | Export-csv -path C:\SCOM_Tasks\Mbx_Above303.csv;
    Send-MailMessage -Attachments "C:\SCOM_Tasks\Mbx_Above303.csv" -To “[email protected]" -From “abc@xyz" -SMTPServer [email protected] -Subject “Mailboxex are above 303 in Exchange databases” -Body “Mailboxex are above 303 in Exchange databases" 
    Mailboxex - is the line which i want to monitor if the values there are above 303. And it will extract the lines with all above 303 to another CSV file and 2nd is a mail script to email me the same with the attachment of the 2nd extract.
    Gautam.75801

  • Unzipping nested files in powershell

    # Initially clear screen
    clear-host
    # Set up initial Paths
    $destination = “C:\Users\paul__000\Documents\Test\unzipped"
    $b = 'C:\Users\paul__000\Documents\Test\Reports\Archive\Adjusted_prices_Reports'
    # Set up working files - for establishing initial directories and files
    $bb = 'C:\Users\paul__000\Documents\Test\Test00.txt'
    $bc = 'C:\Users\paul__000\Documents\Test\Test01.txt'
    # Setup path - keep track of initial directory - and establish path to allow relative addressing
    $a = Get-Location
    Set-Location $b
    # Establish files for both folders and zip files
    get-childitem | format-table name | out-file $bb
    $c =get-content $bb
    $d = $c.count
    # Disgard surplus info & only keep directory and file name information (Not sure why count initially was 31 !!! : hence the need for -3 in next statement)
    $c = $c[3..($d-3)] | out-file $bb
    $c = Get-Content $bb | out-file $bc
    $c = Get-content $bc
    $d = $c.count
    $c = $c[0..($d-1)] | out-file $bc
    $c = get-content $bc
    $d = $c.count
    # establish folder names - by replacing .zip or .ZIP with \
    $d
    $count = 0
    do {
    $c[$count] = $c[$count].replace(".ZIP","\")
    $c[$count] = $c[$count].replace(".zip","\")
    $count=$count + 1
    until ( $count -gt ($d-1) )
    $c | out-file $bc
    $c = get-content $bc
    # Setup path - keep track of initial directory - and establish path to allow relative addressing
    $xxx = Get-Location
    Set-Location ($destination + "\")
    # set up folders
    $d
    $count = 0
    do {
    $k = $c[$count]
    New-Item -itemtype directory -path $k
    $count =$count +1
    until ( $count -gt ($d-1) )
    Set-Location $xxx
    # Establish a Expand-ZipFile function
    function Expand-ZIPFile($file, $destination)
    $file, $destination
    $file = "$file"
    $destination = "$destination"
    # help help help - it looks like i have send the correct parameters but i get the error:
    # You cannot call a method on a null-valued expression.
    # At C:\Users\paul__000\Documents\Powershell rj\Untitled26.ps1:70 char:19
    $shell = new-object -com shell.application
    $zip = $shell.NameSpace($file)
    foreach($item in $zip.items())
    $shell.Namespace($destination).copyhere($item)
    # Establish both - files to unzip and folders to store them in - parameters are passed to 'function Expand-ZIPFile'
    # This is where error occurs
    $c = get-content $bc
    $e = get-content $bb
    $f = $e.count
    $c , $e , $f
    $count=0
    do {
    $e[$count] = $b + '\' + $e[$count]
    $c[$count] = $destination + '\' + $c[$count]
    Expand-ZIPFile –File $e[$count] –Destination $c[$count]
    $count = $count + 1}
    until ($count -gt ($f-1))
    # end of main code
    ## This is standalone code which works successfully
    function Expand-ZIPFile($file, $destination)
    $shell = new-object -com shell.application
    $zip = $shell.NameSpace($file)
    foreach($item in $zip.items())
    $shell.Namespace($destination).copyhere($item)
    $mmm =“C:\Users\paul__000\Documents\Test\Reports\Archive\Adjusted_prices_Reports\PUBLIC_PRICE_REVISION_DISPATCH_20110101.ZIP ”
    $nnn =“C:\Users\paul__000\Documents\Test\unzipped\PUBLIC_PRICE_REVISION_DISPATCH_20110101\"
    Expand-ZIPFile –File $mmm –Destination $nnn
    The main concern is the use of a function called Expand-ZIPFILE which is used for unzipping nested zip files. 2 parameters are supplied, the file to be unzipped and the folder for showing the unzipped files. As it is a nested zip files these are zip files which also need to be unzipped. The code has not been written for this yet. I have placed a stand alone function at the bottom of my code which works perfectly. However when I try and run in the main body of code and pass parameters to the function it fails at line 70. Error message : You can not call a method on a null valued expression. I hope you can assist on this matter.Looking forward to your expert assistance.Roger
    

    Thanks for the code.
    I used it but changed the file and folder locations.
    It appeared to work, however in the 2 successive runs of the code, 2 different errors were announced at the PS Console. The errors are shown as follows:
    Second Run Error Message followed by First Run Error Message
    clear-host
    #File used 'C:\Users\paul__000\Documents\Test\Reports\Archive\Adjusted_prices_Reports\PUBLIC_PRICE_REVISION_DISPATCH_20110101.ZIP' instead of 'c:\scripts\scripts.zip'
    #Directory used 'C:\Users\paul__000\Documents\Test\unzipped\PUBLIC_PRICE_REVISION_DISPATCH_20110101\' instead of 'c:\temp\'
    # load support classes\
    $zipfile='C:\Users\paul__000\Documents\Test\Reports\Archive\Adjusted_prices_Reports\PUBLIC_PRICE_REVISION_DISPATCH_20110101.ZIP'
    [System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression")
    #openand archive
    $archive = New-Object System.IO.Compression.ZipArchive(New-Object System.IO.FileStream($zipfile,'Open'))
    # list contents
    # $archive
    $archive.Entries|select name,length,fullname
    # extract a file
    $entry=$archive.GetEntry('scripts/config.ini')
    # $entry
    $target='C:\Users\paul__000\Documents\Test\unzipped\PUBLIC_PRICE_REVISION_DISPATCH_20110101\'
    # $target
    [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $target+$entry.Name, $true)
    $archive.Dispose();
    # Extract a zipfile
    [System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
    [System.IO.Compression.ZipFile]::ExtractToDirectory('C:\Users\paul__000\Documents\Test\Reports\Archive\Adjusted_prices_Reports\PUBLIC_PRICE_REVISION_DISPATCH_20110101.ZIP','C:\Users\paul__000\Documents\Test\unzipped\PUBLIC_PRICE_REVISION_DISPATCH_20110101\')
    write-host "Results"
    get-childitem 'C:\Users\paul__000\Documents\Test\unzipped\PUBLIC_PRICE_REVISION_DISPATCH_20110101\'
    # create a zip archive
    #[System.IO.Compression.ZipFile]::CreateFromDirectory('c:\scripts','c:\temp\scripts.zip')

  • Search and Replace text in file using PowerShell

    I want to schedule a script in PowerShell to search a directory for an XML file for a particular text string and replace it with a different text string and then save the file with the same name, the name of the file
    will change each time the script is run on a daily basis. There will only be one XML file in the location when the scheduled script is run.
    I have never used PowerShell but am familiar with batch file commands, can anyone please help!!
    KevinS

    Hi Kevin,
    I’m writing to just check in to see if the suggestions were
    helpful. If you need further help, please feel free to reply this post directly so we will be notified to follow it up.
    If you have any feedback on our support, please
    click here.
    Best Regards,
    Anna
    TechNet Community Support

  • How to Compare 2 CSV file and store the result to 3rd csv file using PowerShell script?

    I want to do the below task using powershell script only.
    I have 2 csv files and I want to compare those two files and I want to store the comparision result to 3rd csv file. Please look at the follwingsnap:
    This image is csv file only. 
    Could you please any one help me.
    Thanks in advance.
    By
    A Path finder 
    JoSwa
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful"
    Best Online Journal

    Not certain this is what you're after, but this :
    #import the contents of both csv files
    $dbexcel=import-csv c:\dbexcel.csv
    $liveexcel=import-csv C:\liveexcel.csv
    #prepare the output csv and create the headers
    $outputexcel="c:\outputexcel.csv"
    $outputline="Name,Connection Status,Version,DbExcel,LiveExcel"
    $outputline | out-file $outputexcel
    #Loop through each record based on the number of records (assuming equal number in both files)
    for ($i=0; $i -le $dbexcel.Length-1;$i++)
    # Assign the yes / null values to equal the word equivalent
    if ($dbexcel.isavail[$i] -eq "yes") {$dbavail="Available"} else {$dbavail="Unavailable"}
    if ($liveexcel.isavail[$i] -eq "yes") {$liveavail="Available"} else {$liveavail="Unavailable"}
    #create the live of csv content from the two input csv files
    $outputline=$dbexcel.name[$i] + "," + $liveexcel.'connection status'[$i] + "," + $dbexcel.version[$i] + "," + $dbavail + "," + $liveavail
    #output that line to the csv file
    $outputline | out-file $outputexcel -Append
    should do what you're looking for, or give you enough to edit it to your exact need.
    I've assumed that the dbexcel.csv and liveexcel.csv files live in the root of c:\ for this, that they include the header information, and that the outputexcel.csv file will be saved to the same place (including headers).

  • Split large .pptx file to multiple files using PowerShell

    Hi.
    I'm not a programmer and I have the task to split big .pptx file(>100 slides) to multiple .pptx files with 4 slides in each one and save them into SP library. It should be done on PowerShell.
    Thanks for any help!

    Hi,
    For splitting PowerPoint files into multiple parts, I would suggest you post this question to Office forum, you will get more help and confirmed answers there:
    http://social.technet.microsoft.com/Forums/office/en-US/home
    For uploading files to SharePoint Library using PowerShell, here are some links with script demos provided for your reference:
    http://social.technet.microsoft.com/wiki/contents/articles/19529.sharepoint-2010-upload-file-in-document-library-using-powershell.aspx
    http://spfileupload.codeplex.com/
    Best regards
    Patrick Liang
    TechNet Community Support

  • Parse log file using powershell

    Hi,
    Am pretty new to Powershell and would require anyone of your assistance in setting up a script which parse thru a log file and provide me output for my requirements below.
    I would like to parse the Main log file for Barra Aegis application(shown below) using powershell.
    Main log = C:\BARRALIN\barralin.log
    Model specific log = C:\BARRALIN\log\WG*.log
    Requirements :
    1. scroll to the bottom of the log file and look for name called "GL Daily" and see the latest date which in the example log below is "20150203"
    note : Name "GL Daily" and date keep changing in log file
    2. Once entry is found i would like to have a check to see all 3 entries PREPROCESS, TRANSFER, POSTPROCESS are sucess.
    3. If all 3 are success i would like to the script to identify the respective Model specific log number and print it out.
    E.g if you see the sample log below for "GL Daily", it is preceded by number "1718" hence script should append the model log path with "WG00" along with 1718, finally it should look something like this  C:\BARRALIN\log\WG001718.log.
    4. If all 3 items or anyone of them are in "failed" state then print the same log file info with WG001718.log
    Any help on this would be much appreciated.
    Thank You.
    Main log file :
    START BARRALINK            Check Auto Update                                                1716  
    43006  20150203 
        Trgt/Arch c:\barralin                                               
        PREPROCESS           success   0 preprocessor: no error                   
        TRANSFER             success   1 Host success: files received             
        POSTPROCESS          success   0 Postprocessor: no error                  
        CONFIRMATION         success   2 No Confirm needed                        
    STOP  43105  20150203 
    START Aegis                GL Monthly                                                    
      1716   43117  20150203 
        Trgt/Arch K:\barraeqr\aegis\qnt\gleqty                              
        PREPROCESS           success   0 preprocessor: no error                   
        TRANSFER             success   1 Host success: files received             
        POSTPROCESS          success   0 Postprocessor: no error                  
        CONFIRMATION         success   2 No Confirm needed                        
    STOP  44435  20150203
    START Aegis                UB Daily                                                    
      1717   43107  20150203 
        Trgt/Arch K:\barraeqr\aegis\qnt\gleqty                              
        PREPROCESS           success   0 preprocessor: no error                   
        TRANSFER             success   1 Host success: files received             
        POSTPROCESS          success   0 Postprocessor: no error                  
        CONFIRMATION         success   2 No Confirm needed                        
    STOP  44435  20150203 
    START Aegis                GL Daily                                                    
        1718   44437  20150203 
        Trgt/Arch K:\barraeqr\aegis\qnt\gleqty                              
        PREPROCESS           success   0 preprocessor: no error                   
        TRANSFER             success   1 Host success: files received             
        POSTPROCESS          success   0 Postprocessor: no error                  
        CONFIRMATION         success   2 No Confirm needed                        
    STOP  50309  20150203 
     

    Hi All,
    I was writing a function in power shell to send email and i was looking to attach lines as and when required to the body of the email. but am not able to get this done..Here's my code
    Function Email ()
    $MailMessage = New-Object System.Net.Mail.MailMessage
    $SMTPClient = New-Object System.Net.Mail.SmtpClient -ArgumentList "mailhost.xxx.com"
    $Recipient = "[email protected]"
    If ($MessageBody -ne $null)
    $MessageBody = "The details of Barra $strsessionProduct model is listed below
    `rHostName : $localhost
    `r Model Run Date : $Date
    `r Model Data Date : $DateList1
    `r`n Click for full job log"+ "\\"+$localhost+"\E$\Local\Scripts\Logs "
    $MailMessage.Body = $MessageBody
    If ($Subject -ne $null) {
    $MailMessage.Subject = $Subject
    $Sender = "[email protected]"
    $MailMessage.Sender = $Sender
    $MailMessage.From = $Sender
    $MailMessage.to.Add($Recipient)
    If ($AttachmentFile -ne $null) { $MailMessage.Attachments.add($AttachmentFile)}
    $SMTPClient.Send($MailMessage)
    $Subject = "Hello"
    $AttachmentFile = ".\barralin.log"
    $MessageBody = "Add this line to Body of email along with existing"
    Email -Recipient "" -Subject $Subject -MessageBody $MessageBody -AttachmentFile $AttachmentFile
    as you can see before calling Email function i did add some lines to $MessageBody and was expecting that it would print the lines for $MessageBody in Email Function along with the new line. But thats not the case.
    I have tried to make $MessageBody as an Array and then add contents to array
    $MessageBody += "Add this line to Body of email along with existing"
    $MessageBody = $MessageBody | out-string
    Even this didnt work for me. Please suggest me any other means to get this done.
    THank You

  • Open, Write and Close the file using Powershell

    Hi All,
    I need to create/open a file and write some data into it and close that file.
    Could anyone please help me with this.
    Thanks.

    You don't need to explicitly create, open, or close a file in Powershell.  Here are some ways to write to a file, in addition to New-Item:
    $text = 'Hello World'
    # Create file:
    $text | Set-Content 'file.txt'
    #or
    $text | Out-File 'file.txt'
    #or
    $text > 'file.txt'
    # Append to file:
    $text | Add-Content 'file.txt'
    #or
    $text | Out-File 'file.txt' -Append
    #or
    $text >> 'file.txt'
    Grant Ward, a.k.a. Bigteddy
    The problem with Out-File is that it works like the console. When text is output, it will be truncated if it is wider than the default. So if you are looking for something where you need to store lots of long strings, then you may want to choose a different
    route, or ensure than you specify a width for your output.
    http://technet.microsoft.com/en-us/library/ee176924.aspx
    For example to get 200 characters of width:
    $text | Out-File
    'myfile.txt' -width 200
    I do not know for certain if there is a limit to how wide it can be. I also assume the default is the standard console width (80 characters I believe.)

  • Creating a diskpart script file using Powershell

    Hi,
    I have a very odd (and very annoying) problem...
    I have a powershell script which creates a diskpart file to online any given number of iSCSI attached disks.  The powershell script takes input from a csv which includes the disk numbers then creates a txt file with the relevent diskpart commands (e.g
    select disk X, online disk, etc..)
    The powershell script runs without error and creates the output file, however when I attempt to run diskpart with the outputfile (i.e. diskpart /s outputfile.txt) diskpart does not acknowledge/accept the file and just returns a list of valid commands. 
    Yet if I manually create a empty txt file via Windows Explorer and copy and paste the contents of the powershell generated script file in to it, then run the diskpart against this file all works as expected.
    So it seems as though that in writing to the file via powershell something is happening to the file fortmatting which diskpart does not like - any ideas what?
    I have tried several work arounds including manually creating the txt file before running the powershell and creating the txt file explicitly from powershell but get the same result.
    Although I can workaround the issue as described above it would be nice to get this working as intended, or least understand why the problem occurs - so any help/advice would (as always) be much appreciated!
    for reference the powershell script is detailed below:
    $a="select disk "
    $b="attributes disk clear readonly"
    $c="online disk"
    import-csv .\input.csv | foreach {
     $a+$_.diskNumber >> outputfile.txt
     $b >> outputfile.txt
     $c >> outputfile.txt

    Kazun,
    Thank you for sharing your script. I tired it but did not work for me. I modified yours slightly to configure 134 SAN devices as mount points.   I've already set the SAN policy to OnlineAll and cofigured 4 other devices. When I run the diskpart
    commands per disk from CLI its works. Please let me know what I'm missing.Thank you.
    $B = import-csv -Path "C:\Support\Prep_Disks\3-CreateMountPoints\MountPoints.csv"
    $B | Foreach-Object {
    $DiskNum = $_.DiskNumber
    $MP = $_.MountPath
    $DiskLBL = $_.DiskLabel
    $command = @"
    SELECT DISK $DiskNum
    ATTRIBUTES DISK CLEAR READONLY
    ONLINE DISK
    CONVERT MBR
    CREATE PARTITION PRIMARY
    ASSIGN MOUNT=$MP
    FORMAT FS=NTFS UNIT=64k LABEL=$DiskLBL QUICK
    $command | diskpart

Maybe you are looking for

  • Authenticating a user using AJAX

    Hi, I'm building a login region and would like to build in the authentication process so that a new developer in a team can simply create on of our apps and just create a page that uses this region plugin. Is this possible to do in a single plugin? A

  • FP11 on PartedMagic x64 does not load properly

    Had a need to run flash player on a drive recovery tool. Downloaded the latest x86_64 tar.gz, followed instructions and got this gem: LoadPlugin: failed to initialize shared library /root/.mozilla/plugins/libflashplayer.so [/root/.mozilla/plugins/lib

  • Imovie Format converisionn

    I need to convert the standard MEPG4 movie format into a WMV or MOV format to upload to a web site - how do I do this within the I movie platform?

  • Archive icon?? on email screen

    following an update to iOS 4.2 there is now a new icon on my mail screens (a box with an arrow pointing into it). what is this box, and where do i need to go to retrieve email "swallowed" by it? thanks

  • Lost Photos in iPhoto 11

    Whilst I imported new photos and whilst I identified faces (which is also adding photos) I lost a major part of the photos. Some 20'000 miniatures are still avalable but only about 12'000 originals are available or accessible. It is strange that a pa