Why does my script ignore values in variable only some of the time?

Hello,
I'm a beginner at Powershell and am writing a script to gather the deployment details on all Azure Cloud Services attached to a Azure Subscription, including the info for any service that does not have a deployment.  
I understand that the way I'm going about this may be wrong and I am NOT looking for any help creating a final script.  Some of my script is written specifically so that I can better understand what it's doing (for learning purposes).
What I am looking for is help understand why my current script behaves the way it does.
Here's my current script:
#Create a report that shows the created date and latest deployment date for all
#hosted services (cloud services)deployments in MyAzureSubscription
Select-AzureSubscription MyAzureSubscription
$ServiceNames = Get-azureservice
foreach ($service in $ServiceNames){
$ServiceName = $service | select -ExpandProperty ServiceName
$ServiceDateModified = $service | select -ExpandProperty DateModified
$service |
get-azuredeployment -ErrorAction SilentlyContinue -ErrorVariable NoDeployment |
Select @{Name="ServiceName";Expression={$ServiceName}}, DeploymentName, Status, CreatedTime, LastModifiedTime, @{Name="ServiceDateModified";Expression={$ServiecDateModified}}, @{Name="NoDeployment";Expression={$NoDeployment}} |
Sort-Object -Propert DeploymentName |
export-csv "outputfile.csv" -notypeinformation -append
#Test statements below
#Write-Host "NoDeployment Below:"
#$Service | select ServiceName | Write-Host
#Write-Error $NoDeployment
Write-Host $ServiceName
The output file only contains a list of servicenames and deployment details for services that do have a deployment.  None of the services that have no deployments are added/exported to the csv file.  However, the "write-host $ServiceName"
writes ALL the service names in the powershell window, regardless of whether there's a deployment or not.
What I don't understand is why the Select @{Name="ServiceName";Expression={$ServiceName}} only outputs the service names of services that have deployments instead of ALL service names regardless of whether they have a deployment or not.
I've already proven that the variable $ServiceName does, at some point, save the ServiceName into the $ServiceName variable by writing it to host on each iteration of the foreach loop.  So why is it ignoring some ServiceNames when outputting/exporting
to the csv file?
Thanks!

Hi Landshrkk,
The script only outputs the names of the services that have deployments, because the get-azuredeployment cmdlet encounter error and didn't pass the result to select cmdlet, please try the script below:
$output=@()
Select-AzureSubscription MyAzureSubscription
$ServiceNames = Get-azureservice
foreach ($service in $ServiceNames){
$ServiceName = $service | select -ExpandProperty ServiceName
$ServiceDateModified = $service | select -ExpandProperty DateModified
$s=$service |get-azuredeployment -ErrorAction SilentlyContinue -ErrorVariable NoDeployment
$output += New-Object PSObject -Property @{
ServiceName = $ServiceName
DeploymentName = $s.DeploymentName
Status = $s.Status
CreatedTime = $s.CreatedTime
LastModifiedTime = $s.LastModifiedTime
ServiceDateModified = $ServiecDateModified
NoDeployment = $NoDeployment}
$output|Sort-Object -Propert DeploymentName |export-csv "outputfile.csv" -notypeinformation
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]

Similar Messages

  • My iPhone does not alert every time I receive a text message, only some of the time.  Anyone else have this problem?

    My iPhone 4S does not alert every single time I receive a text message, only some of the time.  The software is all up to date.  Anyone else have this problem?

    There are a number of different alerts that can be played on the iPhone. Have you turned the mute switch on? That is located on the side of the phone. When it is in the down/on position (the orange is showing) you should not get any sound alerts. Also, it could be an SMS, a voicemail, an email, a 3rd party alert (if you have particiular apps that provide alerts). You would need to check all of those settings, but with the mute switch on you should not get any sound alerts.

  • Why does CC update .png files only some of the time?

    I am creating some lower thirds from a template in PS, saving them as .png files and bringing them into the project. When I get updates from our clients, I will make those changes in the .psd, and save over the original .png file. Sometimes CC will update that file in the project without having to re-import and everything is fine. It isnt a huge hassle to just replace the file but Id like to know why it only works some of the time.

    Hi Landshrkk,
    The script only outputs the names of the services that have deployments, because the get-azuredeployment cmdlet encounter error and didn't pass the result to select cmdlet, please try the script below:
    $output=@()
    Select-AzureSubscription MyAzureSubscription
    $ServiceNames = Get-azureservice
    foreach ($service in $ServiceNames){
    $ServiceName = $service | select -ExpandProperty ServiceName
    $ServiceDateModified = $service | select -ExpandProperty DateModified
    $s=$service |get-azuredeployment -ErrorAction SilentlyContinue -ErrorVariable NoDeployment
    $output += New-Object PSObject -Property @{
    ServiceName = $ServiceName
    DeploymentName = $s.DeploymentName
    Status = $s.Status
    CreatedTime = $s.CreatedTime
    LastModifiedTime = $s.LastModifiedTime
    ServiceDateModified = $ServiecDateModified
    NoDeployment = $NoDeployment}
    $output|Sort-Object -Propert DeploymentName |export-csv "outputfile.csv" -notypeinformation
    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]

  • HT204088 why does this very poorly managed site loose my password all the time ???  i put it in correct!!!!!!!!!!!!!!!!!

    i used the correct password but as usual this crappy site screws it up it is 5 times in 3 months?????

    Jglee,
    I can understand how connecting to Wi-Fi is very important to maintain better control of your GB. I appreciate all the troubleshooting you have already tried to get this issue corrected.  Does your 4s have the most current software?  You can check this in setttings: Settings>General>Software Update.  Keep us posted.  We are here to help.
    YareliM_VZW
    Follow us on Twitter at @VZWSupport

  • Why does my form data gets cleared out when clicking on the back button.

    Can someone explain why does my form selections get cleared out when clicking on the back button.
    I have a JSP page that displays a form with some selections and text boxes. I populate the page and submit the request. The action on the submit call another jsp page, which processes the data and displays the results via a <jsp:include> statement which calls the results page. When clicking on the back button from the results page, it returns me to the form page, but the selections are cleared out.
    1. Is there something in my calling of the pages that causes this behavior and can I prevent it?
    I notice that the behavior is different when using the IE 6.0 version Netscape 7.1. IE clears the page Netscape 7.1 retains the settings.
    If I cannot prevent this behavior does that mean I will have to save the state of the form data. And if I have to save the form data, what would be the easiest method of doing this. I'm a beginner to JSP and Java, but have some ASP experience. I don't understand why the back button in a JSP request clears the form data but a regular HTML page does not can someone explain?
    THANKS.

    the browser doesn't have to remember what you submitted and fill that back in.
    you can't prevent it unless you can ensure a new request to the server in which you can fill the default values in there.

  • Why does my iPhone 5 take very grainy flash photographs in the dark will a hard reboot be safe to do to try to fix or is it a hardware issue?

    Why does my iPhone 5 take very grainy flash photographs in the dark will a hard reboot be safe to do to try to fix or is it a hardware issue?
    And By hard boot I mean holding the home and power button down at the same time for 10 seconds or whatever
    I see other people have these grainy flash photographs if you try to take a picture in darkness the picture comes out very dark and grainy I thought the software would ultimately fix this but it's been going on for over a year I usually take my photographs in daylight but I need this to be fixed
    If it is a hardware issue I hope Apple will replace my iPhone 5 because I was just waiting for one of the iOS updates to fix it I bought my phone in November 2012 its the iPhone 5
    Please help or advise if you can was this just a software or hardware issue I know Apple was aware of it but I was advised that iOS update would fix it but obviously not
    Is it safe to do a hard boot on my iPhone five by holding the power and home button at the same time for 10 or 20 seconds I saw someone said that fixed there's at least temporarily
    I'm typing this on my iPhone five right now why do the words go off to the left and right no matter if I hold the phone vertical or horizontal the words bleed off to left right so for me to proofread it I have to move my text left to right to proof read it
    Thank you

    The flash on a smartphone camera is tiny. It only lights up a very small area right in front of the camera. It won't light up the whole scene.
    Have you seen the size of the flash on a professional camera? Even they can't light a whole scene in the dark.
    Fact is, a smartphone camera is not capable of taking good photos in the dark, even with the flash.
    You'll need to buy and learn how to use a professional, dedicated SLR camera to be able to take good photos in the dark. It is not easy.

  • Why does fix capitalization work when there is only one space after the period in pages 09?

    why does fix capitalization work when there is only one space after the period in pages 09?  For example:  "Turn on 3rd St. After the traffic light."  There is only one space after the period in "St."  shouldn't it only auto correct after TWO spaces..??  the word After, should be after..

    You may also use a noBreak space after the period at the end of the abbreviation.
    If I remember well, in such case the capitalization will not apply.
    Yvan KOENIG (VALLAURIS, France) mercredi 27 avril 2011 23:34:46

  • Why does my Apple TV have to frequently reactivate some channels

    Why does my Apple TV have to frequently reactivate some channels, such as HBO Go and PBS and several others that I know were already activated.

    Maybe a software update reset something, maybe the broadcasters require this at intervals, could someone have logged/signed out?  Sorry don't get those channels in UK, but once Netflix made me log in again, others seem ok.
    You could send some feedback if this happens very often:
    Apple - Apple TV - Feedback

  • Why does my iphone send all text from only one of my contacts to my email?

    Why does my iphone send all text from only one of my contacts to my email? I'm curious to know if anyone else has had this issue with the Iphone 5s...

    imessage has a new setting that shows all emails associated with your apple id.  There are two sections, send and receive.  Since you are using the same apple id, Im sure if you adjust one of those settings to your mobile number instead of your appleid, it wont send double.
    You might also have to adjust your wifes settings too, so those emails dont overlap

  • WHY DOES IT ACT LIKE I AM OPENING ITUNES UP FOR THE FIRST TIME

    WHY DOES IT ACT LIKE I AM OPENING ITUNES UP FOR THE FIRST TIME

    dewin1or wrote:
    I want to extend the length of the song by repeating the first 28 measures.
    split the region at the 28th measure
    http://www.bulletsandbones.com/GB/GBFAQ.html#split
    (Let the page FULLY load. The link to your answer is at the top of your screen)
    then select only the first region and option-drag it to the end of the song

  • Why does my Ipad keep going black and then back to the apple logo.  It eventually goes to the start page but then blacks out again.  I have already rebooted several times with no luck!!

    Why does my Ipad 2 keep going black ahd back to the apple logo.  It eventually goes to the home screen and allows me to try something else but after about 30 seconds it happens again.  I have already rebooted several times? 

    Make Sure iOS is updated to the latest version
    Reboot the device by pressing and holding down the home and sleep/wake buttons (power) at the same time until the apple logo appears on the screen, then let go.
    If that doesn't work then reset the device by going to settings/general/reset/reset all settings

  • Why does my iPhoto red eye reduction tool only give me blue or black blobs in the eyeballs that look completely unacceptable?

    Why does my iPhoto red eye reduction tool only give me blue or black blobs in the eyeballs that look completely unacceptable? Automatic mode makes blue blobs that cover iris and even eyelid! Manual mode gives black dots, not at all hte shape of a oerson's iris as seen in a picture.

    And again the answer is simply
    THere is no fix - that is the way it works - you can post as many times as you want but it will not change the fact that that is the way that iPhoto works
    No fix
    No work around
    It is what it is - nothing more - nothing less
    LN

  • Why does Flash Player keep sending me notifications to update to the version I already have?

    Why does Flash Player keep sending me notifications to update to the version I already have? The result is always an error message telling me that the version is already running. (Desktop Computer; Windows Vista OS; Firefox; Adobe Flash Version 11.8.800.94)

    I don't know; can you post a screenshot of such a notification?
    Did you update both ActiveX (for Internet Explorer) and plugin (for Firefox)?

  • Why does my Ipod not synchronize all playlists? Some get synchronized, others don't. Yet there is enough space available.

    Why does my Ipod not synchronize all playlists? Some get synchronized, others don't. Yet there is enough available space.

    The S.I. prefix Giga is used to mean both 1000x1000x1000 and 1024x1024x1024. Computer software typically uses the second version, but using the first number makes the same number of bytes appear bigger when expressed as Gb, so is favoured by hard drive manufactures.
    80Gb10 = 74.3Gb2
    It's a bit like specifying a quantity in gallons without saying whether they are US or Imperial gallons - everybody gets the same volume but one number will be bigger than the other. I could offer you a tank with 10 Imperial gallons of fuel in it - but if I tell you it's 12 US gallons it sounds like you're getting more for your money.
    Once the total size of your library exceeds the capacity of your device all you need to do is create some size limited playlists to determine what goes on the device. Don't sync all movies, sync one or two that you plan to watch soon. Likewise with TV Shows. Limit podcasts to unplayed episodes and finally create a music subset. What worked for me for some time was a smart playlist called Steve's Tunes defined as Playlist is Music and Playlist is not Exclude where Exclude was regular playlist that I would manually add to until Steve's Tunes was small enough to fit. These days I run an iPhone and have a number of smart playlists with ? Gb of most played, ? Gb of highly rated, ? Gb of recently added, ? Gb of essentials, ? Gb of unplayed etc. Each time I sync I get slightly updated selection without having to put any extra effort in.
    tt2

  • Why does siri come on by itself while it sits on the table no one touching it?

    why does siri come on by itself while it sits on the table no one touching it?

    michael jfromtaunton wrote:
    why does siri come on by itself while it sits on the table no one touching it?
    If you're not running iOS 8 as you describe you are not, and Siri keeps coming on, this could be a hardware failure of the Home Button.
    Try these steps:
    Basic Troubleshooting Steps when all else fails
    - Quit the App by opening multi-tasking bar, and swiping the App upward to make it disappear.  (For iOS 6 older, hold down the icon for the App for about 3-5 seconds, and then tap the red circle with the white minus sign.)
    - Relaunch the App and try again.
    - Restart the device. http://support.apple.com/kb/ht1430
    - Reset the device. (Same article as above.)
    - Reset All Settings (Settings > General > Reset > Reset All Settings)
    - Restore from backup. http://support.apple.com/kb/ht1766 (If you don't have a backup, make one now, then skip to the next step.)
    - Restore as new device. http://support.apple.com/kb/HT4137  For this step, do not re-download ANYTHING, and do not sign into your Apple ID.
    - Test the issue after each step.  If the last one does not resolve the issue, it is likely a hardware problem.

Maybe you are looking for