Kiran

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 234 total)
  • Author
    Posts
  • Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    Okay, if it isn’t Hyper-V then what Rob suggested is the ideal way, but still, it can be in this way as well…

    $vhost = “10.16.14.25”
    
    [pscustomobject]@{ VMCount = (Get-VMHost -Name $vhost | Get-VM).Count }
    
    
    Thank you.
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    This way it is even simpler…

    $vhost = “10.16.14.25”
    
    $myvmcount = (Get-VM -ComputerName $vhost).Count
    
    [pscustomobject]@{ VMCount = $myvmcount }
    
    

    Thank you.

     

    in reply to: Splatting with dot notation. #243320
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    Thanks @kvprasson!

    Yeah, the concept is good, but it’s not suitable for my scenario, because some of the cmdlets don’t support ValueFromPipeline attribute properties, so I have to use splatting or passing the parameters directly. So I have to use an intermediate variable.

     

    in reply to: Splatting with dot notation. #242696
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    Yes, it works like this…

    
    
    $r = @{
          process = [PSCustomObject]@{Name='lsass'}
          path    = [PSCustomObject]@{Path = 'c:\'}
         }
    [PSCustomObject]$r.Process | Get-Process
    [PSCustomObject]$r.Path | Get-ChildItem

    Thanks, Prasoon!

    • This reply was modified 3 weeks, 1 day ago by Kiran.
    in reply to: Splatting with dot notation. #242693
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    Thanks Rob, even I have been searching but couldn’t be figured it out. Looks like there is no workaround for this.

    in reply to: Splatting with dot notation. #242684
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    Thanks Prasoon! But still, I can’t add a new configuration/property since its an object.

    in reply to: Splatting with dot notation. #242597
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    What if I have $splat like this…

    
    
    $splat = @{
        Name = @{
            FirstName = 'John'
            LastName = 'Smith'
        }
        Favorites = @{
            Color = 'Red'
            Hobby = 'Curling'
        }
    }
    in reply to: enum failing when used as a type in param() #241865
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    You can also use the ValidateSet attribute like this as well…

    class SupportedCountries : System.Management.Automation.IValidateSetValuesGenerator
    {
    [string[]] GetValidValues()
    {
    ## Write your code here
    $Countries = @(‘India’, ‘USA’, ‘UK’, ‘Canada’, ‘Australia’)
    return $Countries
    }
    }
    
    Function Get-Country
    {
    [CmdLetBinding()]
    param
    (
    [parameter(Mandatory = $true)]
    [ValidateSet([SupportedCountries])]
    [string] $CountryName
    )
    
    ## Write your code here
    Write-Host $CountryName
    }
    in reply to: How to send/copy files from a folder to URL https:// #241817
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    Try with Invoke-RestMethod or Invoke-WebRequest

    Thanks.

    in reply to: Powershell script works only from a specific folder #241814
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    Please post your code wrapping with PRE tags and also take a look at ImportExcel module…

    https://www.powershellgallery.com/packages/ImportExcel/7.1.0

    in reply to: enum failing when used as a type in param() #241808
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero
    Command = '/ISSERVER "\"\SSISDB\DW\Data Warehouse ETL\DW Master ETL.dtsx\"" /SERVER "\"D01\DEV\"" /Par "\"$Project::DWDatabaseConnectionString\"";"\"Data Source=SQLD01\DEV01;Initial Catalog=reporting_devaca1;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;\"" /Par "\"$Project::IsDailyLoad(Boolean)\"";False /Par "\"$Project::IsStandardEdition(Boolean)\"";False /Par "\"$Project::SourceDatabaseConnectionString\"";"\"Data Source=SQLVD01\DEV01;Initial Catalog=devtesttest;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;\"" /Par "\"$ServerOption::LOGGING_LEVEL(Int16)\"";2 /Par "\"$ServerOption::SYNCHRONIZED(Boolean)\"";True /CALLERINFO SQLAGENT /REPORTING E'
    
    Try running the command directly and see the results.
    
    Also, try using the ValidateSet or ArgumentCompleter attributes instead is enum.
    
    Thank you.
    
    
    
    in reply to: could you please release my post from moderation? #235306
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    Yeah, it’ done.

    And no clue at all why it is happening to you all alone.

    So, hire me. 😋😋😂

    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    That’s great! I was asking you to ensure that there is no firewall block.

    And you must provide the credentials when it is outside of your domain network whether it is by name or ip.

    Thank you.

    in reply to: Error with string processing #232786
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    Hi coulbc59

    I am not an expert in Exchange Server though, but for your requirement to manage with the strings in the arguments you can run the command like below…

    Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery ‘from:”$emailaddress”‘ -TargetMailbox Cleanup -TargetFolder Processed -DeleteContent -LogLevel Full
    And please format the code using PRE tags to highlight the code.
    Thank you.
    Moderator
    Topics: 4
    Replies: 234
    Points: 1,276
    Helping Hand
    Rank: Community Hero

    @Tom – Since the remote server is not domain joined, you need to authenticate the server, so use -Credential parameter and pass the credentials with the Invoke-Command.

    And I hope there is no firewall block. And by any chance did you try using IP address??

    Thank you.

     

Viewing 15 posts - 1 through 15 (of 234 total)