none
get the pc name with domain name and add it to my properties file using commands RRS feed

  • Question

  • i want to get the pc name with domain name and add it to my properties file using powershell  .

    sid

    Friday, September 12, 2014 9:35 AM

Answers

  • you could do something like this:

    $env:COMPUTERNAME + "." + $env:USERDNSDOMAIN | Out-File c:\properties.txt -Append -Force

    or something loke this:

    $comp = gwmi win32_computersystem
     $comp.Name + "." + $comp.Domain | Out-File c:\properties.txt -Append -Force

    HTH, Ben


    • Edited by Ben GelensMVP Friday, September 12, 2014 1:14 PM code block
    • Proposed as answer by Ben GelensMVP Friday, September 12, 2014 1:14 PM
    • Marked as answer by sidhanttiwari Tuesday, September 16, 2014 2:55 AM
    Friday, September 12, 2014 9:42 AM
  • function Get-Environment{
        [environment]|Get-Member -Static -MemberType Properties |
            ForEach-Object{
                if($_.Name -ne 'StackTrace'){
                      $v=[scriptblock]::Create("[environment]::$($_.Name)").Invoke()
                      New-Object PsCustomObject -Property ([ordered]@{Name=$_.Name;Value=$v[0]})
                }
            }
    }
    Get-Environment
    Get-Environment | Out-String | Out-File environment.txt


    ¯\_(ツ)_/¯



    • Edited by jrv Friday, September 12, 2014 10:55 AM
    • Marked as answer by sidhanttiwari Tuesday, September 16, 2014 2:55 AM
    Friday, September 12, 2014 10:53 AM

All replies

  • you could do something like this:

    $env:COMPUTERNAME + "." + $env:USERDNSDOMAIN | Out-File c:\properties.txt -Append -Force

    or something loke this:

    $comp = gwmi win32_computersystem
     $comp.Name + "." + $comp.Domain | Out-File c:\properties.txt -Append -Force

    HTH, Ben


    • Edited by Ben GelensMVP Friday, September 12, 2014 1:14 PM code block
    • Proposed as answer by Ben GelensMVP Friday, September 12, 2014 1:14 PM
    • Marked as answer by sidhanttiwari Tuesday, September 16, 2014 2:55 AM
    Friday, September 12, 2014 9:42 AM
  • function Get-Environment{
        [environment]|Get-Member -Static -MemberType Properties |
            ForEach-Object{
                if($_.Name -ne 'StackTrace'){
                      $v=[scriptblock]::Create("[environment]::$($_.Name)").Invoke()
                      New-Object PsCustomObject -Property ([ordered]@{Name=$_.Name;Value=$v[0]})
                }
            }
    }
    Get-Environment
    Get-Environment | Out-String | Out-File environment.txt


    ¯\_(ツ)_/¯



    • Edited by jrv Friday, September 12, 2014 10:55 AM
    • Marked as answer by sidhanttiwari Tuesday, September 16, 2014 2:55 AM
    Friday, September 12, 2014 10:53 AM