Azure powershell script runs locally bu not in webjob

I downloaded Azure commandlets locally and changed the Azure website size by just running an Azure powershell script i wrote. However, uploading it to run as a webjob on my Azure website it fails with the same errors it did locally Before installing Azure
Powersehll. Looking in kudu I see windows powershell but no azure powershell. Do I need to install Azure powershell to my website somehow?

Done! >And it already got some attention :)
http://feedback.azure.com/forums/169385-websites/suggestions/7155775-add-azure-commandlets

Similar Messages

  • Powershell script run with TaskScheduler not stopping VM's

    I have a script that stops and starts the VM's, and copies files and it works ok when I run it with powershell, but when I run it with TaskScheduler, it's not stopping/starting the VM's (but does copy files).  We have server 2008 R2.  I updated
    powershell to version 3 and downloaded and installed the Hypver-V powershell module from Microsoft.
    Also, when I run the script through powershell, I needed to run as administrator.  When I run it with the powershell prompt this is what it looks like:
    C:\windows\system32> powershell -NoProfile -noninteractive -ExecutionPolicy bypass -Command "& c:\Scripts\BackupVhdShell_2_param.ps1 -single_backup_file_to_loc 'E:\' -single_backup_file_from_loc 'S:\SQL-bak.vhd'"
    So that works from powreshell to start/stop vm's and copy files.
    In Task Scheduler, this is how I have it set up:
    Run with highest priviledges is checked. I have my login credentials saved so it can wake up the server when I'm not here or if it's not up.  
    In The Program/script field: %SystemRoot%\SysWow64\WindowsPowerShell\v1.0\powershell.exe
    In the Add Arguments field: -NoProfile -noninteractive -ExecutionPolicy bypass -Command "& c:\Scripts\BackupVhdShell_2_param.ps1 -single_backup_file_to_loc 'E:\' -single_backup_file_from_loc 'S:\SQL-bak.vhd'"
    Any thoughts?  I'm not sure if TaskManager isn't finding HyperV module?
    This is what the majority of the script looks like:
    param($single_backup_file_to_loc, $single_backup_file_from_loc)
    function StopVMsInOrder ([array][String]$vmNames){ 
    #this function will stop VM's in list, sequentially 
       Write-Host "Processing virtual machines in order"
       foreach ($name in $vmNames) {
           Write-Host "Analyzing $name"
           Try {
                 #Write-Host "...Saving $name"
                 #Save-VM -VM $name -wait -Force
                 Write-Host "..shutdown $name" #name)"
                 Invoke-VMShutdown -VM $name -Force #$vm.name
           } #try
           Catch {
              Write-Host "Failed to get virtual machine $name"
           } #catch
       }#foreach
    } #function StopVMsInOrder
    function StartVMsInOrder ([array][String]$vmNames){ 
    #this function will start VM's in list, sequentially as opposed to all at once
       Write-Host "Processing virtual machines in order"
       foreach ($name in $vmNames) {
           Write-Host "Analyzing $name"
           Try {
                 Write-Host "..Starting $name"
                 Start-VM -VM $name -wait
           } #try
           Catch {
              Write-Host "Failed to get virtual machine $name"
           } #catch
       }#foreach
    } #function StartVMsInOrder
    function CopyFileToFolder ([string]$Source,[string]$destination){  
       # get filename  
    #################start of script##############
    import-module Hyperv
    #get list of running vm's
    [array]$vmNames = @(Get-VM -Running | %{$_.elementname})  
    Write-Host "To: $single_backup_file_to_loc"
    Write-Host "From: $single_backup_file_from_loc"
    #call function to stop vm's
    StopVMsInOrder $vmNames      
    if($single_backup_file_to_loc -ne " ")
       #someone passed in a parameter for one-off use of script
       [array]$destFileArray = @($single_backup_file_to_loc)
       [array]$sourceFileArray = @($single_backup_file_from_loc)
    }else
       Write-Host "To Loc not Defined as param"
       #get set up for what need to backup vhd's
       #where back it up to
    $i=0
    for ($i = $sourceFileArray.GetLowerBound(0); $i -le $sourceFileArray.GetUpperBound(0); $i++) { 
            $tempSource =  $sourceFileArray[$i]
            $tempDest = $destFileArray[$i]
            CopyFileToFolder $tempSource $tempDest
            Write-Host "i: $i"
    Write-Host "Done with vhd backup"
    #call function to start vm's
    StartVMsInOrder $vmNames  
    Write-Host "Done with vm start"
    Michele Cleary

    I finally figured it out!  I changed it so I was using the 32 bit version of powershell in TaskScheduler:  %SystemRoot%\system32\....  Now it's finding the VM's!
    Michele Cleary
    Just FYI - system32 is x64. SysWOW64 is x86.
    Don't retire TechNet! -
    (Don't give up yet - 12,700+ strong and growing)

  • I created a script to add logos to photos at a club and now when I run the script, the script runs but does not actually place anything on the photo itself.  What's going on?

    I created a script to add logos to photos at a club and now when I run the script, the script runs but does not actually place anything on the photo itself.  What's going on?

    He meant post it here, of course, Louie!  How on Earth would you post it "on Photoshop" ? 
    Thank you for the belly laugh. 

  • PowerShell Script running Excel won't run on Windows Server 2008 R2

    I have a script that creates a report of a single example of each warning or error in the Windows Event log, for each server in a list of servers,with the number of times that error has occurred in the last week on each server. It creates this report in
    Excel. I have this script running automated through Task Scheduler for one client on Windows 7 and it's working perfectly. I have another client that I am attempting to run this script automated on a server running Windows Server 2008 R2. I can manually run
    the script and everything works, but if I try to schedule the script everything works except for the Excel PowerShell commands. I've have tried:
    Created the Desktop folders for config\systemprofile in System32 and in SysWOW64.
    Configured permissions in DCOM for Microsoft Excel Application.
    Configured folder permissions for config\systemprofile.
    Verified PowerShell is working.
    Unchecked the option in the task to only run while logged on.
    Does anyone have any idea why this is happening and how I can fix it? Thanks!
    Sincerely,
    Christopher Beard

    You might have to launch the application once as the system account so that it can set up the Excel environment, I've had the same problem when  trying to update Excel files from an admin Powershell console using my admin account.  Use psexec with
    a -s option to run it as system account locally while logged on to the target server:
    psexec -s "c:\program files (x86)\microsoft office\office14\excel.exe"
    Then you'll most likely be prompted to input initials - which is what I suspect is preventing your code from running properly.
    There may be some other more elegant way to handle this, but you'd be better off asking that question in one of the forums devoted to Office products.
    I hope this post has helped!

  • Multi-Select Script Runs in ISE, not on remote Hyper-V Server

    Hello All!
    I've created  a powershell script to allow a user to launch one of several management tools on a Hyper-V server. The script runs fine in Powershell ISE on my system (none of the tools work, obviously) but when I run it on the remote server, these errors
    come up:
    At C:\Mgmt\MgmtSel.ps1:70 char:1
    + }
    + ~
    Unexpected token '}' in expression or statement.
    At C:\Mgmt\MgmtSel.ps1:72 char:1
    + }
    + ~
    Unexpected token '}' in expression or statement.
    At C:\Mgmt\MgmtSel.ps1:73 char:1
    + }
    + ~
    Unexpected token '}' in expression or statement.
    + CategoryInfo : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken
    When I paste it directly into the Powershell window, it runs fine. So strange! I know my brackets are correct, or it wouldn't run when pasted into the shell or in ISE. Anyway, any help you could provide would be appreciated. Thank you all for your time!
    Here's the script:
    <######################################################################
    Present user with options to launch one of several management programs
    Save as MgmtSel.ps1 in c:\Mgmt
    v 0.1 Basic Menu Presentation for different management tools
    Written By Ricky Carleton
    Based on code by Paul Westlake
    ######################################################################>
    $xAppName = ‘MgmtSel’
    [BOOLEAN]$global:xExitSession=$false
    function LoadMenuSystem(){
    [INT]$xMenu1=0
    [INT]$xMenu2=0
    [BOOLEAN]$xValidSelection=$false
    while ( $xMenu1 -lt 1 -or $xMenu1 -gt 4 ){
    CLS
    #… Present the Menu Options
    Write-Host “`n`tLogin Management Tools Selection – Version 0.1`n” -ForegroundColor Magenta
    Write-Host “`t`tPlease select the admin area you require`n” -Fore Cyan
    Write-Host “`t`t`t1. sconfig console” -Fore Cyan
    Write-Host “`t`t`t2. Corefig” -Fore Cyan
    Write-Host “`t`t`t3. Hyper-V Mgmt” -Fore Cyan
    Write-Host “`t`t`t4. Quit and exit`n” -Fore Cyan
    #… Retrieve the response from the user
    [int]$xMenu1 = Read-Host “`t`tEnter Menu Option Number”
    if( $xMenu1 -lt 1 -or $xMenu1 -gt 4 ){
    Write-Host “`tPlease select one of the options available.`n” -Fore Red;start-Sleep -Seconds 1
    Switch ($xMenu1){ #… User has selected a valid entry.. load next menu
    1 {
    CLS
    Write-Host “`t`tStarting sconfig`n” -Fore Cyan
    start c:\Windows\System32\sconfig.cmd
    2 {
    CLS
    Write-Host “`t`tStarting Corefig`n” -Fore Cyan
    C:\Corefig\COREFIG.PS1
    3 {
    while ( $xMenu2 -lt 1 -or $xMenu2 -gt 3 ){
    CLS
    # Present the Menu Options
    Write-Host “`n`tSelect the Hyper-V Mgmt Tool you would like to use`n” -Fore Cyan
    Write-Host “`t`t`t1. PSHVM30” -Fore Green
    Write-Host “`t`t`t2. ProHVM (not working yet)” -Fore Green
    Write-Host “`t`t`t3. Go to Main Menu`n” -Fore Green
    [int]$xMenu2 = Read-Host “`t`tEnter Menu Option Number”
    if( $xMenu1 -lt 1 -or $xMenu1 -gt 3 ){
    Write-Host “`tPlease select one of the options available.`n” -Fore Red;start-Sleep -Seconds 1
    Switch ($xMenu2){
    1 {
    CLS
    Write-Host “`t`tStarting PSHVM`n” -Fore Cyan
    call powershell -WindowStyle Hidden C:\PSHVM30\hyperv.ps1
    2 {
    CLS
    Write-Host “`t`tStarting Corefig (For now, later, ProHVM)`n” -Fore Cyan
    start C:\Corefig\COREFIG.PS1
    default { Write-Host “`n`tYou Selected Option 3 – Go to Main Menu`n” -Fore Yellow; break}
    default { $global:xExitSession=$true;break }
    LoadMenuSystem
    If ($xExitSession){
    Exit-PSSession #… User quit & Exit
    } Else {
    C:\Mgmt\MgmtSel.ps1 #… Loop the function

    How are you running the script on the server? Pasting into the ISE on the server, saving as a script and running it from the command line on the server? Or something else?
    When you say you paste it into the PowerShell window and it runs fine, is this PowerShell window on your machine or the server? How are you pasting it (RDP? Teamviewer? VNC?).
    It appears that some of the characters are not being saved/pasted correctly. You could try paste into notepad first and make sure all the characters are correct there, then select all and paste into the window on the server, or use noteapad to save the document
    as a regular text file before copying to the server.

  • Using Powershell Script Run simple query in MS Access 2007 and export the results of query to Excel

    Hi Experts,
    I have a Access 2007 DB file and 2 Big tables inside that (bigger than the size that can be easily handled by MS Excel 2007).
    My requirement is automate using powershell scripts the below things.
    1. Create a SQL query in Access DB and save that in access DB
    2. Run the saved query and export the result in excel sheet where I can create the charts and Pivots. Thanks in advance
    Prajesh

    Do you have to use the Access query, couldn't you just recreate the query in Powershell?  Here's a link with good info that references an existing script for querying an Access database:
    http://blogs.technet.com/b/heyscriptingguy/archive/2009/08/13/hey-scripting-guy-can-i-query-a-microsoft-access-database-with-a-windows-powershell-script.aspx
    Once you have your dataset you can pipe it to
    Export-Csv -NoType c:\pathtofile\output.csv

  • Azure SQL database working locally but not when published to Azure

    I have an
    AngularJS  solution that is connecting to a SQL Azure database.  When
    I run the solution locally, it’s configured to connect up to the SQL Azure database, the solution works fine. However,
    when I publish the solution to Azure the connection to the SQL Azure database does not work.
    When debugging with Chrome I get the error Failed to load resource: the server responded with a status of 500 (Internal Server
    Error) 
    I'm not using EF. but dapper.
    My connectionstring is as follows
    <add name="PortalConnection" providerName="System.Data.SqlClient" connectionString="Server=tcp:xxx.database.windows.net,1433;Database=xxx;User ID="xxx";Password="xxx";Trusted_Connection=False;Encrypt=True;Connection
    Timeout=30;"/>
    When I run the web solution locally from Visual Studio, my sql queries runs like it should, it's only the published version having problems. 
    Any ideas?
    Software Developer

    Hi,
    Thanks for answer.
    I had followed that step by step guide for deploying to Windows Azure. So that was not the problem.
    But I was able to get a better error message by turning off custom error in web.config.
    I got the error message: "Windows login are not supported in this version of SQL Server"
    I solved this by using the SqlConnectionStringBuilder instead of getting the connection string from 
    web.config.
    So everything works great now, just think it's strange it worked locally before..
    Regards
    -entery
    Software Developer

  • Powershell script to modify DNS not returning errors

    I've modified a script to make DNS changes given a name/IP combo from a CSV file and it seems to be working, but is not throwing any errors (which I had thought it would do, but doesn't)
    ## Directions:
    ## Script Requires DnsShell 0.4.4 http://dnsshell.codeplex.com/
    ## Script Uses Get-Dns and New-DnsRecord
    ## csv file must be in following format including the proper first line headers
    ## Name,IPAddress
    ## eample_a_record,127.0.0.1
    Write-Host "Enter Name the Path to the CSV File>"
    $CSV = read-host
    Write-Host "Enter Name the DNS Server>"
    $ServerName = read-host
    Write-Host "Enter the Domain example: domain.local>"
    $ForwardLookupZone = read-host
    $filename = "D_ERRLOG{0:yyyyMMdd-HHmm}.txt" -f (Get-Date) #error Log
    Write-Host "Enter The Reverse Domain Octet example 168.192 or 10 for 10.in-addr.arpa.>"
    $TReverseLookupZone = read-host
    $ReverseLookupZone = $TReverseLookupZone + ".in-addr.arpa."
    # Import CSV and create A record
    Import-Csv $CSV | ForEach-Object{
    $record = get-dnsrecord -name $_.name -recordtype A -zonename $forwardlookupzone -Server $ServerName
    if ($record.name) {get-dnsrecord -name $_.name -recordtype A -zonename $forwardlookupzone -Server $ServerName | Remove-DnsObject -force | out-file ./$filename -Append}
    New-DnsRecord -name $_.name -recordtype A -zonename $forwardlookupzone -IPaddress $_.IPAddress -Server $ServerName | out-file ./$filename -Append
    #create reverse record
    New-DnsRecord -Name $_.IPAddress -Hostname ($_.name + '.' + $forwardlookupzone) -Zonename $ReverseLookupZone -Type PTR -Server $ServerName | out-file ./$filename -Append
    Write-Host -foreground "yellow" "Any Errors will be in the file $filename"
    The out-file is blank, every time. I've even forced errors but it's still blank.
    Any ideas? 
    Thank you.
    [email protected]

    Hi,
    Just checking in to see if the suggestion was helpful. Please let us know if you would like further assistance.
    TechNet Subscriber Support
    If you are
    TechNet Subscription
    user and have any feedback on our support quality, please send your feedback
    here.
    Regards, Yan Li

  • Bash script run via cron not executing MYSQL command

    I have a bash script which is run from a cron,
    It is executing as I have it write to a log file which it does correctly.
    I am wanting the bash script to restore a mysqldump file.
    When I run the bash script manually the dump file gets loaded fine. But when I run it through the cron the mysql command appears to be ignored.
    The mysqldump file is 54MB and I have checked to make sure that MYSQL is included in the global users path in /etc/profile
    Does anyone know why this maybe??
    Here is the bash file
    #!/bin/bash
    date >> /home/user/crons/crons.log
    echo "Started loadbackup" >> /home/user/crons/crons.log
    cd /home/user
    dbuser=root
    dbpass=password
    dbname=databasename
    filename=backup
    mysql -hlocalhost -u"$dbuser" -p"$dbpass" "$dbname" < " >> /home/user/crons/crons.log
    My crontab looks like
    02 17 * * * /home/user/crons/loadbackup.sh
    Many thanks
    Richard

    Hi Richard,
    Have you tried redirecting the script output in the cron to see if an error is being reported?
    I.e.
    02 17 * * * /home/user/crons/loadbackup.sh > /tmp/loadbackup.log 2>&1

  • Cannot Create New Share from Azure PowerShell - The remote name could not be resolved

    I have created a storage account. It seems that there isn't a specific way to create file storage rather than blob storage.
    I followed the instruction for creating a share in Azure Power Shell but when I try $s=New-AzureStorageShare... I keep getting the error "The remote name could not be resolved".  I checked the account name and it matched what is shown on the
    Azure site.
    I also cannot access the storage from the URL's.  I get the message "This page can't be displayed.
    How can I create a file storage account and a share to it?
    Thanks,
    Glen

    Hi Glen,
    Thanks for your post!
    Did you sign up your File Service ?
    To sign up, go to the Microsoft Azure Preview Portal, and sign up for the Microsoft Azure Files service using one or more of your subscriptions. As subscriptions
    are approved for the Azure File preview, you will get an email notifying you of the approval. We will be slowly opening up the service to users in batches, so please be patient after signing up.
    After sign up and enable this feature, I suggest you could refer to this blog for how to use Azure File service (
    http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/12/introducing-microsoft-azure-file-service.aspx#faq7 ).
    Regards,
    Will
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • FLV files run locally but not on website

    My flash video plays back when I do a preview, but after uploading the FLV files and the new page to the web site all I have are blank squares, not videos. What's up?

    Your welcome

  • PowerShell scripts and Azure

    Please forward if this is not the correct forum.
    I'm trying to create Azure Powershell scripts that can be executed on a scheduled basis, however an authentication popup is always displayed before the commands can be executed. I've tried importing my publishersettings file, specifying the management certificate,
    etc.
    Can someone please paste a sample script below to simple run start-azurevm which includes commands to authenticate without user interaction?
    Also include where the certificates, ... come from.
    Thank you,
    David
    David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.

    Hi,
    If you are using in an automation script and want to avoid any pop up window, please try the following snippet.
    $userName = "<your organizational account user name>"
    $securePassword = ConvertTo-SecureString -String "<your organizational account password>" -AsPlainText -Force
    $cred = New-Object System.Management.Automation.PSCredential($userName, $securePassword)
    Add-AzureAccount -Credential $cred
    If I misunderstand, please feel free to let me know.
    Best Regards,
    Jambor
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • System.Drawing.Bitmap in a scheduled powershell script

    I've written a powershell script to date stamp multipage tiffs, but I check to make sure the file name follows the correct format before doing so. The file name must contain the date, sequence number, and number of pages. The script works fine when run manually,
    but when run from task scheduler it fails to query the number of pages in the TIFF. Any ideas why the .NET features wouldn't work from a powershell script run as a scheduled task?
    I am putting the page number in the variable "count" by doing the following:
     $i=[System.Drawing.Bitmap]::FromFile($file.Fullname);$i.GetFrameCount($i.FrameDimensionsList[0]) 
     $count=$i.GetFrameCount([System.Drawing.Imaging.FrameDimension]::Page)
    FULL SCRIPT FOLLOWS
    #Define the input and output folders and date format
    $Original_TIFFs="C:\scans"
    $Modified_TIFFs=";\\test\Shared\SDS\"
    $date = get-date -Format d
    $datename=Get-Date -format yyyyMMdd
    Set-Location $Original_TIFFs
    #Configure email settings
    $emailFrom = "removed"
    $emailTo = "removed"
    $smtpServer = "removed"
    $body = "Rename scanned claims file to the correct format. This email was sent from: ", $env:computername
    #Define the location of the TIFF command line executable and its parameters
    $200DLL='C:\TiffDLL200Commandline\Cmd200.exe '
    $arg1='"FILE='
    #Modify arg2 to put the output directory in front of the ; if don't want to overwrite current file
    #$arg2=';|OW=Yes|BITS=2|TEXT=2;Received Date: '
    $arg2=$modified_TIFFs
    $arg3=';|BITS=2|TEXT=2;Received Date: '
    $arg4='|TEXTOPS=-5;;10;14;"'
    $files=Get-ChildItem $Original_TIFFs -Filter *.tif
    if ($files -eq $null)
      $subject = "No files to process today, directory empty."
      $smtp = new-object Net.Mail.SmtpClient($smtpServer)
      $body = "No files were processed today. This email was sent from: ", $env:computername
      $smtp.Send($emailFrom, $emailTo, $subject, $body)
    else
    foreach ($file in $files)                                                                  
       #Begin loop to check each file and process
     #Loads subsystems for opening TIFFs and second line puts the number of images into variable
     $i=[System.Drawing.Bitmap]::FromFile($file.Fullname);$i.GetFrameCount($i.FrameDimensionsList[0]) 
     $count=$i.GetFrameCount([System.Drawing.Imaging.FrameDimension]::Page)
     #If statement checks if filename format is correct
     if ($file -match '^\d{8}\d{3}_H_S_\d+_\d{8}[.tif]{4}$')
      $file.name -match '^(?<date1>\d{8})\d{3}_H_S_(?<page_count>\d+)_(?<date2>\d{8})[.tif]{4}$'   #Regex to put tests in $matches to check against
      if (($matches.date1 -eq $datename) -and ($matches.date2 -eq $datename))                      #Check if filename contains correct date
      if ($count -eq $matches.page_count)                                                          #Check if filename
    contains the correct page count
       #insert TIFF modification
        $allargs=$200Dll+$arg1+$file+$arg2+$file+$arg3+$date+$arg4
        cmd /c $allargs
        #cmd /c xcopy $file \\test\shared\SDS                                                   #Deprecated because now having
    TIFF200DLL create a new file rather than overwrite
        $i.Dispose()                                                                  
                #Close file stream so file can be deleted: http://support.microsoft.com/kb/814675
        Remove-Item $file.Name
        #Next section is for a different output directory; Setup a seperate batch file to delete original TIFFs in the middle of the night
        <#
        $allargs="cmd200 "+$arg1+$file+";"+$Modified_TIFFs+";"+$arg2+$date+$arg3
        cmd /c $allargs
        #>
        else                                                                    
                     #else statement to send out error message if the number of pages differs from name
        $subject = "The number of pages in the file ", $file.FullName, "differs from the actual count of ", $count, ". File will not be sent, please correct before tomorrow for processing."
        $smtp = new-object Net.Mail.SmtpClient($smtpServer)
        $smtp.Send($emailFrom, $emailTo, $subject, $body)
      }  #Close IF/THEN for correct date is in filename
     else
        $subject = "Date portion of filename is incorrect, please fix. File will not be sent to SDS", $file.FullName," ."
        $smtp = new-object Net.Mail.SmtpClient($smtpServer)
        $smtp.Send($emailFrom, $emailTo, $subject, $body)
     }                                                    #Close IF/THEN for initial filename check
     else
        $subject = "File does not meet proper naming convention and will not be stamped nor sent to SDS", $file.FullName, " ."
        $smtp = new-object Net.Mail.SmtpClient($smtpServer)
        $smtp.Send($emailFrom, $emailTo, $subject, $body)
    }                                                     #Close FOR loop
    }                                                     #Close Else for check if FILES=NULL

    You are buikding thisin the ISE?
    You need too add:
    add-type -AssemblyName System.Drawing
    ¯\_(ツ)_/¯

  • Remote PowerShell script execution from web page

    I am building a web interface for Active Directory for a school project. (It will NOT touch the Internet, it is for intranet use.) I want to click a "button" on my interface and execute a PowerShell script on a server. (example: Clicking on "AD Users" would execute a PS script to get a list of users) Does anyone know a good approach to accomplish this? I can nandle writing the PowerShell scripts, I am just not sure what the best way to call them from a web interface would be. Any reference or information would be appreciated.

    hi igor
    i am actually working on a simillar project , i'm planning to publish it as an open source in codeplex
    the idea is that you have to know another programming language like VB , C# ... in my case i used ironpython
    ASP.NET , while ironpython calls powershells command using system.managment.automation through runspace
    iron python only handles the web interface stuff , like button click events , and handling output stuff from powershell
    you can convertto-html cmdlet from powershell it will make your life alot easier :)
    G

  • Get-Item: Cannot find path ' ' because it does not exist. While running Powershell script.

    I am trying to run a PowerShell script to upload files into a SharePoint site in an Azure environment...the script works fine on my local machine, but every time I run it in Azure (remotely), I get errors. Here is what my simple script looks like...
    if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
    Write-Host "Loading Sharepoint Module "
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    Add-PSSnapin -Name Microsoft.SharePoint.PowerShell
    if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell) -eq $null )
    Write-Host "Failed to load sharepoint snap-in. Could not proceed further, Aborting ..."
    Exit
    #Script settings
    $webUrl = "http://sampleWebUrl"
    $docLibraryName = "My Documents"
    $docLibraryUrlName = "My%20Documents"
    $localFolderPath = get-childitem "C:\Upload\Test Upload\My Documents\" -recurse
    $contentType = "ContenttType1"
    #Open web and library
    $web = Get-SPWeb $webUrl
    write-host "Web:" $web
    $docLibrary = $web.Lists[$docLibraryName]
    write-host "docLibrary:" $docLibrary
    $files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()
    write-host "files:" $files
    If ($contentType = "ContenttType1")
    #Open file
    $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()
    # Gather the file name
    $FileName = $File.Name
    #remove file extension
    $NewName = [IO.Path]::GetFileNameWithoutExtension($FileName)
    #split the file name by the "-" character
    $FileNameArray = $NewName.split("_")
    $check = $FileNameArray.Length
    #Add file
    $folder = $web.getfolder($docLibrary.rootFolder.URL)
    write-host "Copying file " $file.Name " to " $folder.ServerRelativeUrl "..."
    $spFile = $folder.Files.Add($folder.Url + "/" + $file.Name, [System.IO.Stream]$fileStream, $true)
    $spItem = $spFile.Item
    write-host "Success"
    write-host "SP File:" $spFile
    write-host "SP Item" $spItem
    #populate columns
    $spItem["Column1"] = $FileNameArray[0]
    $spItem["Column2"] = $FileNameArray[1]
    $spItem.Update()
    $fileStream.Close();
    Again, I can run this on my local machine and it works just fine, but when I attempt to run it on the Azure environment I get this error...
    Get-Item : Cannot find path 'C:\powershellscripts\12653_B7045.PDF' because it does not exist.
    At C:\PowerShellScripts\Upload-FilesIntoSharePointTester.ps1:32 char:42
    +     $files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()
    +                                          ~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (C:\powershellscripts\12653_B7045.PDF:String) [Get-Item], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
    What strikes me first is the fact that the file its looking for is in the "C:\Upload\Test Upload\My Documents\" directory, but the error keeps saying "C:\powershellscripts\" which is where my script resides and not the files I want to
    upload into SharePoint. When I step through the code, all the variables are holding the correct values. The $localFolderPath shows the name of files that I am attempting to upload, so it recognizes them. But once I step through this particular line of code,
    the error occurs...
    $files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()
    Is this an error caused because I am remoting into the Azure environment? Has anyone dealt with this issue before? I would really appreciate the help. Thanks
    Update: quick thing I noticed is that these two lines of code are returning null values. Again, is this handled differently in Azure or remotely? I ask cause this is the way I know how to do this, locally.
    $docLibrary = $web.Lists[$docLibraryName]
    $files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()

    "...square brackets are wildcard characters in Windows PowerShell..."
    When you use cd without a parameter it uses the -Path parameter. In this case you'll have to escape the square brackets so they are not considered wildcards. Each of the commands in the first example does the exact same thing.
    cd 'Learn PowerShell `[Do Whatever`]'
    cd -Path 'Learn PowerShell `[Do Whatever`]'
    cd (or Set-Location) also has a literal path parameter (-LiteralPath) that does not require using an escape character (`) before each of the brackets. Hope this helps.
    cd -LiteralPath 'Learn PowerShell [Do Whatever]'

Maybe you are looking for