Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Unable to run powershell commands from Run Window

$
0
0

Hi All,

I am trying to Run a powershell command from run window instead of going to powershell.

I want to Run the below command:

New-Object System.Net.Sockets.TcpClient("Localhost", 5723)

The above command will let me know if the port 5723 is open in localhost.

The command runs fine when i run it using the powershell Window as in the below screenshot:

When i try to run the same command from Run window i use the below:

Powershell.exe -noexit -command New-Object System.Net.Sockets.TcpClient("Localhost", 5723)

I get the error as "The term 'Localhost' is not recognized as a cmdlet"

Can any one let me know what am i doing wrong here ?


Gautam.75801


Help with Azurestorageblobcopy and the URI it demands

$
0
0

Hi all,

I'm trying to use a medialink property from a get-AzureOSDisk to put into a Start-AzureStorageBlobCopy, but the -srcUri field isn't accepting it since the medialink uri includes in it the port.

the get-azureOSDisk.medialink uri looks like this(sorry for the weird URL - I cannot post links since my account isnt verified):

httpsWACKWACKmystaccount.blobDOTcoreDOTwindowsDOTnet:8080/vhds/diskname.vhd

While the -srcUri field in Start-AzureStorageBlobCopy will only accept: "httpsWACKWACKmystaccountDOTblobDOTcoreDOTwindowsDOTnet/vhds/diskname.vhd"


I'm trying to write a script to regulate those kinds of copies, so I can just get the URL and change it manually.

Any thoughts?

Thanks.

P.S.: My PS Script so far(when I use it this way, I'm getting an error: "Start-AzureStorageBlobCopy : The underlying connection was closed: An unexpected error occurred on a send.". The error doesnt occur if I remove the port from the URI)

#azure subscription ID

$subid="subscription id"

#Names of the storage accounts
   $SourceAccount="source account"
   $DestAccount="dest account"

#cloud service and name Of the VM to copy and destroy
   $VMname="vm name"
   $CSname="cs name"

select-AzureSubscription -Subscriptionid $subid


#Get the primary access keys of the storage accounts and put them in $sourcekey and $destkey
   $sourcekey=Get-azurestoragekey -StorageAccountName $SourceAccount
   $sourcekey=$sourcekey.Primary

   $Destkey=Get-azurestoragekey -StorageAccountName $DestAccount
   $Destkey=$Destkey.Primary

#Create contexts for both storageaccounts

$sourceContext = New-AzureStorageContext  –StorageAccountName $SourceAccount -StorageAccountKey $sourcekey
$destContext = New-AzureStorageContext  –StorageAccountName $DestAccount -StorageAccountKey $Destkey

#Create a new container in the destination container

New-AzureStorageContainer -Name "$($vmname)-vhds" -Context $destContext

#Get the OS disk properties and copy it

$OSDisk=get-azurevm -servicename $CSname -name $VMname | Get-azureosdisk

$sourceBlobUri = $OSDisk.medialink

Start-AzureStorageBlobCopy -srcUri $sourceBlobUri -SrcContext $sourceContext -DestContainer "$($vmname)-vhds" -DestBlob "$($osdisk.DiskName).vhd" -DestContext $destContext

Update History not refreshed when installing updates via script?

$
0
0

Hi all

Have you noticed that when installing updates via Script
(http://blogs.technet.com/b/heyscriptingguy/archive/2009/03/11/how-can-i-search-for-download-and-install-an-update.aspx)
with
"$Installer = New-Object -ComObject Microsoft.Update.Installer"
the "Update History" and "Updates were installed" Date gets not refreshed.

The only way to look for installed updates is via Programs and Features -> Show installed updates.

1. Is this a normal behaviour when installing updates with this script?
2. Is there any code to add to the script to get the history updated after installing updates?

Replacing "New-Object -ComObject Microsoft.Update.Installer" with wuauclt.exe /updatenow is not an option because W2012 Server does not accept this command anymore with GPO for "Download and Notify for Install" WSUS Option.

Thank you for your ideas!

BR, qwerdm

Simple Powershell query not working to list Online Computer object in specific OU.

$
0
0

People,

I'm trying to list newly built Windows Server 2012 R2 that is still online in the default Computers OU using the below script:

Get-ADComputer -LDAPfilter {
   Enabled -eq $True -and
   OperatingSystem -like "*2012*" -and
   Name -notlike "PC*" -and
} -SearchBase "CN=Computers,DC=domain,DC=com" | Where-Object { Test-Connection $_.Name -Count 1 -Quiet } | Select -ExpandProperty Name

but somehow I cannot get any result ?

I've checked manually that there is several Windows Server 2012 R2 with the name like PRODAPPS03-VM, PRODLYNC02-VM, etc.... but why the script not returning anything ?


/* Server Support Specialist */

Pinging and getting info on ad computers then output to a file

$
0
0

Hello,

I have this code below that outputs the results in my console but I want to get it to output the results to a text file just as it is in the console. I know it must be something simple but I cant seem to figure it out.

I would like to run this on a schedule every night and have results saved to a text file then that text file be emailed to me.

PowerShell experts please help me.

This script is just the part that gets the info I know how to do the schedule and email part already.

$a= Get-Content "C:\Users\willsh10\Desktop\comp.txt"



foreach ($I in $a)

 

 

{


$rtn= $null





$rtn= Test-Connection "$i" -Count 1 -BufferSize 16 -Quiet





IF ($rtn -match 'True') {write-host "$i Online"}




ELSE{ Write-host "$I Offline"}




Get-ADComputer $I -Properties description

  }






PowerShell Update-Help Problems

$
0
0

While updating the help files I keep getting this error.

-------------------------------------------------- 
PS C:\WINDOWS\system32> Update-Help
Update-Help : Failed to update Help for the module(s) 'StorageReplica' with UI culture(s) {en-US} : Unable to retrieve
the HelpInfo XML file for UI culture en-US. Make sure the HelpInfoUri property in the module manifest is valid or
check your network connection and then try the command again.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.UpdateHelpCommand

Update-Help : Failed to update Help for the module(s) 'NetworkController' with UI culture(s) {en-US} : Unable to
connect to Help content. The server on which Help content is stored might not be available. Verify that the server is
available, or wait until the server is back online, and then try the command again.
At line:1 char:1
+ Update-Help
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToConnect,Microsoft.PowerShell.Commands.UpdateHelpCommand

-------------------------------------------------

and upon looking into the "HelpInfoUri property" located in "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\StorageReplica\storagereplica.psd1"
I discover that the link is   HelpInfoUri="http://go.microsoft.com/fwlink/?LinkID=216862" 

-------------------------------------------------

Additional info:

PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.0.10240.16384
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.42000
BuildVersion                   10.0.10240.16384
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3

Wait for the excel refresh to complete before executing save (next) step

$
0
0

I am opening the excel file from PS and performing "refresh all", then "save" and "quit"

I would like to wait till the "Refresh All" is completed prior to executing "Save"

I have a brute force approach that kinda works with Sleep. Is there a programmatic way to do the wait till "Save All" is completed? 

$workSheet = $workBook.Sheets.Item("OtherRef")
$workSheet.Select()
$workBook.RefreshAll()
Start-Sleep -s 30
$workBook.Save()

$excelObj.Quit()

Thanks in Advance.

Niranjan


Create in memory CSV file

$
0
0

Hi, 

I need a way to create a CSV file in memory. I am reading some data and saving it in an array. Now if I use Export-Csv, I need to pass a physical path for the file but instead I want to create its file in memory.

Can any one please help me with it.


Get-qadGroupMember doesn't write all the result to file

$
0
0

Hi,

I have created a script to loop into each group and fetch the users to export the DisplayName, Description etc etc... but the result doesn't write all the result to file..

$Groups = Get-Content -Path C:\Scripts\GroupName.txt Foreach ($Member in $Groups) { Get-QADGroupMember -Identity $Member | Select DisplayName,Description | Out-file C:\All.txt


But if remove the | Out-File it displayed all the result fine...

Appreciate your help...

Regards,

get user MobilePhone and write to variable

$
0
0

Hi !

How do i get  ad user MobilePhone and write to variable?

Thanks,

Aviv Hassidim

Renaming a WHS server ; Powershell ?

$
0
0

Hi.

I need to rename my WHS 2011 ; it's impossible to do it directly (ie the  rename computer box is grayed).

Is there a way around using powershell ? Shall I need to reconnect the various computers by reinstalling the console ?

Thx in adavnce


FG

Hide verbose output from dependent module

$
0
0
Hi. I developed a module, that is helps me to automate some routine tasks in Configuration Manager 2012, and of course my module uses cmdlets from Configuration Manager module. The cmdlets of my module has verbose output, but after installing SP2 for SCCM, its cmdlets gets his own verbose output. So, when i run my cmdlet with -verbose argument, SCCM cmdlet starts to output his data too, which i don't want to see. So the question is - "How to prevent verbose output from SCCM cmdlets, and see only data from my cmdlets?"

P.S. Sorry for my English

How do I determine if the -split operator was successful?

$
0
0

Hello,

Im using the statement below to split a piece of data based on the occurence of the  '_' character.  What variable can I query or how can I tell the -Split operator worked and found a '_' without relying on querying the contents of $SamName?  I'd like to be sure each time the -Split runs it indeed finds a '_' in the data?

Foreach ($Entry in $Directory) {

 $SamName = ($Entry.Name -Split '_')0.substring(0)

..... }

I read about_Split and didnt find anything relative to my question.


Thanks for your help! SdeDot

Get Navigator (browser) geolocation - Script

$
0
0

Hi,

Does anyone knows about some powershell script to get latitude & longitude info if wifi card is enabled?  I read about some scripts to get lat x long as from ip address, but it's not what i need. 

In w3schools website has a javascript to get lat x long information as from browser (navigator)

http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation

This link above return my exactly geolocation. i just enable my wi-fi card and it's works.

I need some powershell script to do the same.

Thanks


get-adgroupmember timeout from 2012r2 server? corrupt powershell??

$
0
0

ok, I have a 'script' server where we run a bunch of scheduled tasks from and everything was working great, until i started getting alerts that i baked into my script a couple of days ago.

so after some investigating... i have narrowed it down. 

$foo = Get-AdGroupMember -identity $group -server $domain

where the group and domain vars are populated earlier in the script.

i get the error that "The operation returned because the timeout limit was exceeded" when trying to run it manually from a ps prompt (or ise)

Reboot didn't resolve either and nothing in the event log. (and it is the same for multiple users which are domain admins)

the same command returns in about 5 seconds when i run it from my win7 desktop - it has about 800 members

has anyone seen this before, is my powershell instance corrupt?? 


Remove computer asset from Active Directory and SCCM 2012 - Powershell

$
0
0

I am trying to modify the following script to allow me to:-

  1. Read from a list of computers in a csv
  2. Delete each computer from Activedirectory & SCCM 2012

I have very limited powershell experience, so any help would be greatly appreciated :)

Thanks Adi

# Environment setup
# Import the ActiveDirectory module to enable the Get-ADComputer CmdLet
Import-Module ActiveDirectory

$sccmServer = SCCMServer
$sccmSite = Site
$computerName = Import-CSV -Path Assets.csv

# find and delete the computer from AD
ForEach ($pc in $computers) {
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.filter = "(&(objectclass=computer)(name=$computerName))"
$search.findall() | %{$_.GetDirectoryEntry() } | %{$_.DeleteObject(0)}

# find and delete from SCCM
$comp = get-wmiobject -query "select * from SMS_R_SYSTEM WHERE Name='$computerName'" -computername $sccmServer -namespace "ROOT\SMS\site_$sccmSite"
$comp.psbase.delete()
 }
# spit out results
Write-Host "Deleted $computerName from AD. Removed $computerName from SCCM server $sccmServer, site $sccmSite"

List upates to users

$
0
0

Hi,

I am a Powershell novice so please bare with me.

I need to interogate my local AD to identify all updates to a particular user say within the last month.

I am looking for a good script example that I can use to do this.

Any advise and help will be greatly appreciated.

thanks

List users in OU (sort and exceptions)

$
0
0

I am trying to get a list of all users in each OUs we have (usually one user OU per location) and i would like to exclude some OUs that contain special accounts



I have started with the following lines of code but they present me with 2 issues:

  • the users are not sorted per OU but appear randomly in the result
  • it doesn't exclude the OUs for functional accounts and service accounts even though the DN of these users contain the string i am trying to exclude.

Here is the code part:


$OU=@('DC=corp,DC=group,DC=local')
$ou | foreach { get-aduser -searchbase $_ -Filter {enabled -eq $true} | ? {$_.DistinguishedName -notlike "*,OU=Functional Accounts,*" -or $_.DistinguishedName -notlike "*,OU=Service Accounts,*"} | Select-Object Name, SamAccountName }


ConvertFrom-SecureString fails in remote powershell session even though WSManCredSSP is configured for both client and server.

$
0
0

In this very simple example below I execute a command to Convert a test string To/From a Secure string.  It works fine if I run it locally, or use remote desktop to log into a remote server and run it, however if I  enter a remote powershell session and execute the command it fails with the security error shown in the example below.  I have configured bi-directional CredSSP access on both the client and server computers but it still fails.  Can someone explain why this simple command does not work when run in a remote powershell session?  Is their something else I need to do to enable user account delegation?  The local machine is running Windows 7 WMF 5.0 Production Preview and the server is running Windows 2008 R2 WMF 5.0 RTM.

Any assistance with this issue will be greatly appreciated.

EXAMPLE:
C:\>ConvertTo-SecureString -String 'Test String' -Force -AsPlainText | ConvertFrom-SecureString
01000000d08c9ddf0115d1118c7a00c04fc297eb01000000c90caa672ea9614e8da7249b0f77d0c20000000002000000000003660000c000000010000000a51aac030390359404ee3cd758797f710...
C:\>Get-WSManCredSSP
The machine is configured to allow delegating fresh credentials to the following target(s): wsman/TestRemoteServer
This computer is configured to receive credentials from a remote client computer.
C:\>Enter-PSSession TestRemoteServer
[TestRemoteServer]: PS C:\Users\testadminuser\Documents> Get-WSManCredSSP
The machine is configured to allow delegating fresh credentials to the following target(s): wsman/TestLocalMachine
This computer is configured to receive credentials from a remote client computer.
[TestRemoteServer]: PS C:\Users\testadminuser\Documents> ConvertTo-SecureString -String 'Test String' -Force -AsPlainText | ConvertFrom-SecureString
The requested operation cannot be completed. The computer must be trusted for delegation and the current user account must be configured to allow delegation.
    + CategoryInfo          : NotSpecified: (:) [ConvertFrom-SecureString], CryptographicException
    + FullyQualifiedErrorId : System.Security.Cryptography.CryptographicException,Microsoft.PowerShell.Commands.ConvertFromSecureStringCommand

[TestRemoteServer]: PS C:\Users\testadminuser\Documents>


Rick

How do I force delete a file in PowerShell?

$
0
0

I'm trying to delete a file and get "The File Name(s) would be too long for the destination folder".  As I'm doing shift-delete there is no recycle bin, so what's the destination folder?

Can anyone suggest a way to force the removal please, perhaps using PowerShell?  I think the file was created in Linux and now sits on the SAN I administer.  I cannot rename it, or move it up a level.

Thanks!

Viewing all 21975 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>