Quantcast
Channel: Windows PowerShell Forum
Viewing all 2562 articles
Browse latest View live

installedOn property missing from get-wmiobject win32_quickfixengineering

$
0
0

Hi!

I'm trying to retrieve the installed date for patches but it seems that powershell get-wmiobject win32_quickfixengineering is not showing the installedOn value while wmic qfe list full shows the installedon value.

I'm not familar with wmi console... is there any workaround for this?

 


Querying multiple subdomains for users with Get-ADUser

$
0
0

Good Morning All,

I created a script that will take usernames from a TXT file and populate a CSV with properties found from Get-ADUser.  The script works fine, but will only return results if the user exists on the same domain as I am connected to by default.  How can I have it search multiple subdomains?

Example:

domain1.ad.viacom.com

domain2.ad.viacom.com

Secondly, there is a special case I will run into if I can get this working.  If a username exists on both domains but is in fact 2 different people. 

Examaple:

domain1\doej

domain2\doej

I assume the original text file will need to include "domain1\" or "domain2\" preceeding the username and I would have to parse this information somehow.  What would I use to point it to a specific domain to return the valid results? 

Thank you for any help / suggestions that can be offered.

Problems writing AT command to internal modem with System.IO.Ports.SerialPort.....

$
0
0

Hey all,

I've come seeking some powershell help, specifically with the System.IO.Ports.SerialPort class...

(Code is at end of this post)

I'm creating a script to go in and run an AT command on a specific selection of win32_potsmodem devices.

Up until the point of the actual writing of the AT command to the COM port, it seems everything is fine.

The problem is that I will test run the script once, it will work without throwing an error, and exit fine.

If i immediately, or shortly (within a minute or 2) rerun the script, it fails with an unhandled exception.

I've used try/catch , and some basic diag output to narrow it down to the actual writeline command.

I can't seem to find the graceful way to handle the IO to the COM port, but when it does run without error, it works - so i know the script is 'generally' good in terms of what im looking to acheive. Need some help figuring this out, and had 3 people with more powershell knowledge than me to look at it , and they havent been able to figure it out (though theyve helped narrow the problem to the actual .write method..)

I have some screencaps to illustrate the inconsistent results from this script:

1st test run (notice how the serialport still spits back info after the error, albeit a bit of delay):

2nd test run, this time i hit close on the powershell error before the serialport can spit back info, and this is the error i get:

3rd time, still using the exact same script (waiting 1-2 mins): (will upload in 2nd comment)

So needless to say, there is something i am not handling appropriately here...

I think it's either the add_datareceived codeblock, or something with how i am actually handling the write of the AT command to the port...

Any help would be much appreciated!

Code:

cls ;
$allWINmodems = "" ;
$COMportF = "" ;
$COMport = "" ;
[boolean]$wanmodem = $false ;
[string]$wanCOM = "" ;
[string]$targetCOM = "" ;
$allWINmodems = Get-WMIObject win32_potsmodem ;
foreach ($COMportF in $allWINmodems) {
	If ($COMportF.caption.ToLower() -ilike "*modem1*") { 
		$wanmodem = $true ;
		$wanCOM = $COMportF.AttachedTo.ToString() ;
	}
	ElseIf ($COMportF.caption.ToLower() -ilike "*modem2*") { 
		$wanmodem = $true ;
		$wanCOM = $COMportF.AttachedTo.ToString() ;
	}
}
If ($wanmodem = $false) { Throw "No applicable WAN modems detected - exiting..." }
Else { 
	Write-Host ;
	Write-Host "Detected COM port for WAN wireless card:   $wanCOM" ;
	Write-Host ;
}
$COMport = $null ;
$COMport = New-Object System.IO.Ports.SerialPort $wanCOM,9600,None,8,one ;
Do {
	Write-Host "waiting for port to close..." ;
	Start-Sleep -Milliseconds 1000 ;
} while ($COMport.IsOpen -ne $false)
$COMport.add_DataReceived({`$this is a handle to SerialPort. $_ is a pointer to SerialDataRecievedEventArgs})  ;
If ($COMport.IsOpen -ne $true) { 
	Write-Host "Attempting to open COM port..." ;
	$COMport.Open() ;
}
Do {
	Write-Host "waiting for port to open..." ;
	Start-Sleep -Milliseconds 1000 ;
} while ($COMport.IsOpen -ne $true)
Start-Sleep -Milliseconds 2000 ;
$COMport.WriteLine("ATI") ;
$COMport.WriteLine("`r") ;
#$COMport.WriteLine("ATI" + "`r") 
Start-Sleep -Milliseconds 3000 ;
$storedinfo = $COMport.ReadExisting() ;
Write-Host $storedinfo ;
#$COMport.Close()
#Do {
#	Write-Host "waiting for port to close..."
#	Start-Sleep -Milliseconds 1000
#} while ($COMport.IsOpen -ne $false)
# apparently it is not necessary to manually close the port
	


Jamie Courtes MCTS - SCCM 2007 MCTS - SCCM 2012

Array that moves files dynamically based on date.

$
0
0

OK, so I am new at powershell, and I am having an issue getting my script to run.

Here is what it is supposed to do:
Move all files out of a set of folders to another set of folders. Inside of the destination set of folders, there are extra folders being made daily that are named according to this date format : yyyyMMdd (Script 1), this is running fine and runs separately from the moving script. I am trying to use an array to provide the function with the destination and source file path, then run a function that actually does the moving. This function will check to ensure that the pathways exist before they do the moving and provide fault checking (Script 2). Most of the second script's function is what I found online and tried to change a few things to make it work.  Unfortunately, I get an error in the first line of the function and cannot find what I am doing wrong.

Script1

$date = Get-Date -Format yyyyMMdd
$marwinsql = "\\10.1.152.254\shares\data"
$cc = "\conrad_trans"
$sc = "\stcenter_trans"
$tc = "\toledo_trans"
$tr = "\toledo_rehab"
$mc = "\mtown_clinic"
# -----------------Conrad Clinic--------------------------------------
New-Item "$marwinsql $cc \205\ $date" -name $date -itemtype directory
New-Item "$marwinsql $cc \503\ $date" -name $date -itemtype directory
New-Item "$marwinsql $cc \537\ $date" -name $date -itemtype directory
# -----------------State Center Clinic---------------------------------
New-Item "$marwinsql $sc \334\ $date" -name $date -itemtype directory
New-Item "$marwinsql $sc \437\ $date" -name $date -itemtype directory
New-Item "$marwinsql $sc \462\ $date" -name $date -itemtype directory
New-Item "$marwinsql $sc \568\ $date" -name $date -itemtype directory
# -----------------Toledo Clinic----------------------------------------
New-Item "$marwinsql $tc \135\ $date" -name $date -itemtype directory
New-Item "$marwinsql $tc \502\ $date" -name $date -itemtype directory
New-Item "$marwinsql $tc \562\ $date" -name $date -itemtype directory
New-Item "$marwinsql $tc \563\ $date" -name $date -itemtype directory
New-Item "$marwinsql $tc \43563\ $date" -name $date -itemtype directory
# -----------------Toledo Rehab-----------------------------------------
New-Item "$marwinsql $tr \813\ $date" -name $date -itemtype directory
New-Item "$marwinsql $tr \836\ $date" -name $date -itemtype directory
New-Item "$marwinsql $tr \860\ $date" -name $date -itemtype directory
New-Item "$marwinsql $tr \878\ $date" -name $date -itemtype directory
# -----------------Marshalltown Clinic----------------------------------
New-Item "$marwinsql $mc \146\ $date" -name $date -itemtype directory
New-Item "$marwinsql $mc \298\ $date" -name $date -itemtype directory
New-Item "$marwinsql $mc \565\ $date" -name $date -itemtype directory
New-Item "$marwinsql $mc \701\ $date" -name $date -itemtype directory
New-Item "$marwinsql $mc \744\ $date" -name $date -itemtype directory
New-Item "$marwinsql $mc \746\ $date" -name $date -itemtype directory
New-Item "$marwinsql $mc \748\ $date" -name $date -itemtype directory
New-Item "$marwinsql $mc \779\ $date" -name $date -itemtype directory
New-Item "$marwinsql $mc \796\ $date" -name $date -itemtype directory
New-Item "$marwinsql $mc \798\ $date" -name $date -itemtype directory

Script 2

#------------Set Date-------------------------
$date = Get-Date -Format yyyyMMdd
#------------Source Server file path array--------
$source = @( 	
			"\\10.1.152.249\c$\Export\Conrad Clinic\205\",
			"\\10.1.152.249\c$\Export\Conrad Clinic\503\",
			"\\10.1.152.249\c$\Export\Conrad Clinic\537\",
			"\\10.1.152.249\c$\Export\State Center\334\",
			"\\10.1.152.249\c$\Export\State Center\437\",
			"\\10.1.152.249\c$\Export\State Center\462\",
			"\\10.1.152.249\c$\Export\State Center\568\",
			"\\10.1.152.249\c$\Export\Toledo\135\",
			"\\10.1.152.249\c$\Export\Toledo\502\",
			"\\10.1.152.249\c$\Export\Toledo\562\",
			"\\10.1.152.249\c$\Export\Toledo\563\",
			"\\10.1.152.249\c$\Export\Toledo\43563\",
			"\\10.1.152.249\c$\Export\Toledo Rehab\813\",
			"\\10.1.152.249\c$\Export\Toledo Rehab\836\",
			"\\10.1.152.249\c$\Export\Toledo Rehab\860\",
			"\\10.1.152.249\c$\Export\Toledo Rehab\878\",
			"\\10.1.152.249\c$\Export\Marshalltown\146\",
			"\\10.1.152.249\c$\Export\Marshalltown\298\",
			"\\10.1.152.249\c$\Export\Marshalltown\565\",
			"\\10.1.152.249\c$\Export\Marshalltown\701\",
			"\\10.1.152.249\c$\Export\Marshalltown\744\",
			"\\10.1.152.249\c$\Export\Marshalltown\746\",
			"\\10.1.152.249\c$\Export\Marshalltown\748\",
			"\\10.1.152.249\c$\Export\Marshalltown\779\",
			"\\10.1.152.249\c$\Export\Marshalltown\796\",
			"\\10.1.152.249\c$\Export\Marshalltown\798\"
			)
#-------------Destination Server file path array------
$destination = @(
			"\\10.1.152.254\shares\data\conrad_trans\205\$date",
			"\\10.1.152.254\shares\data\conrad_trans\503\$date",
			"\\10.1.152.254\shares\data\conrad_trans\537\$date",
			"\\10.1.152.254\shares\data\stcenter_trans\334\$date",
			"\\10.1.152.254\shares\data\stcenter_trans\437\$date",
			"\\10.1.152.254\shares\data\stcenter_trans\462\$date",
			"\\10.1.152.254\shares\data\stcenter_trans\568\$date",
			"\\10.1.152.254\shares\data\toledo_trans\135\$date",
			"\\10.1.152.254\shares\data\toledo_trans\502\$date",
			"\\10.1.152.254\shares\data\toledo_trans\562\$date",
			"\\10.1.152.254\shares\data\toledo_trans\563\$date",
			"\\10.1.152.254\shares\data\toledo_trans\43563\$date",
			"\\10.1.152.254\shares\data\toledo_rehab\813\$date",
			"\\10.1.152.254\shares\data\toledo_rehab\836\$date",
			"\\10.1.152.254\shares\data\toledo_rehab\860\$date",
			"\\10.1.152.254\shares\data\toledo_rehab\878\$date",
			"\\10.1.152.254\shares\data\mtown_clinic\146\$date",
			"\\10.1.152.254\shares\data\mtown_clinic\298\$date",
			"\\10.1.152.254\shares\data\mtown_clinic\565\$date",
			"\\10.1.152.254\shares\data\mtown_clinic\701\$date",
			"\\10.1.152.254\shares\data\mtown_clinic\744\$date",
			"\\10.1.152.254\shares\data\mtown_clinic\746\$date",
			"\\10.1.152.254\shares\data\mtown_clinic\748\$date",
			"\\10.1.152.254\shares\data\mtown_clinic\779\$date",
			"\\10.1.152.254\shares\data\mtown_clinic\796\$date",
			"\\10.1.152.254\shares\data\mtown_clinic\798\$date"
			)
#-----------counter/loop through-------------
$i = 0
$x = $source.length-1
while ($i -lt $x)
{
moveFileToFolders
$i +=1
}
#------------move file-----------------------
Function moveFileToFolders ([String]$source[$i], [String]$destination[$i]) #-imports the source/destination locations from Array
{
if (Test-PatH $destination -PathType Container)
{
  foreach ( $srcObj in (get-childitem $source )) 
  { 
    $srcObjPath = "$($srcObj.fullname)"
    $destObjPath = "$($destination)\$($srcObj.name)" 
    If((Test-Path -LiteralPath $destination)) 
     {
       copy-item $srcObjPath $destination -recurse
       if ( (Test-Path -Path $destObjPath ) -eq $true)
       {
        if ( (compare-object (gci $srcObjPath -recurse) (gci $destObjPath -recurse)) -eq $null)
        {
         write-output "Compare is good. Remove $($srcObjPath)"
         remove-item $srcObjPath -recurse
        }
        else
        {
          write-output "Compare is bad. Remove $($destObjPath)"
          remove-item $destObjPath -recurse
         }
       }
       else 
       { 
        write-output "$($destination) path is bad" 
       }
     }
  else
  {
    write-output "bad destinaton: $($destination)"
  }
 }
}
}

If anyone has any help, that would be great.

Thanks,

TJ

How do I copy an Outlook appointment to a shared Calendar?

$
0
0

I am trying to create and appointment in Outlook 2007, using PowerShell and I would like to also copy this appointment to my team's shared calendar.

$outlook = new-object -comobject outlook.application
$calendar = $outlook.Session.folders.Item("myemail@aol.com")
$appt = $calendar.Items.Add(1) # == olAppointmentItem
$appt.Start = [datetime]"10/31/2012 17:00"
$appt.End = [datetime]"10/31/2012 18:00"
$appt.Subject = "TEST - Testing the Calender"
$appt.Location = "TEST"
$appt.Body = "Ignore This. I am testing the calendar"
$appt.Categories = "TEST-Category"
$appt.RequiredAttendees = 'myteamate1@aol.com;myteamate2@aol.com'
$appt.OptionalAttendees = 'mymanager@aol.com'
$appt.ReminderSet = $true
$appt.ReminderMinutesBeforeStart = 120
$appt.BusyStatus = 0 # == The user is available; 2=Busy; 3=OOO; 1=Tentative
$appt.Save()

This part works well in that it creates an appointment in my calendar for me.

I would like to copy it to my Team Shared Calendar.
I tried using $appt.CopyTo() and $appt.Move() to no avail.
I do not know what parameters to pass to it. According to Get-Member:
CopyTo  Method  _AppointmentItem CopyTo (MAPIFolder, OlAppointmentCopyOptions)
Move    Method  IDispatch Move (MAPIFolder)

When I CopyTo with just the 'MAPIFolder' (and I am pretty sure even this part is wrong), I get:
Cannot find an overload for "CopyTo" and the argument count: "1".
At line:1 char:13
+ $appt.CopyTo <<<< ($b)
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

When I add a numeric value for the OlAppointmentCopyOptions (anything), I get no error, but I also do not see anything happening.

I got my MAPIFolder by doing the following:
$calendardest = $outlook.Session.folders.Item("Public Folders - myemail@aol.com")
$calff = $calendardest.Folders
foreach($c in $calff) {
    $a=$c.Name
    if($c.Name -eq 'Favorites') {
        $b=$c.Folders
    }
}
$appt.CopyTo($b,0)

Any help on this will be appreciated.

Trouble with Function

$
0
0

Hello all,

I am trying to create a function that can be used to clear out the AD group memberships for an identified user.  Here is what I have currently.

 $samaccountname ='*' + $(Read-Host 'Please Enter the username') + '*'
Function RemoveMemberships
 {
 	param([string]$SAMAccountName)  
 
 		$user = Get-aduser -filter * -properties samaccountname,memberof| where-object {$_.samaccountname -like "*$samaccountname*"} 
 
 		$userGroups = $user.memberof
 		$userGroups | ForEach-Object {get-adgroup $_ | Remove-ADGroupMember -confirm:$false -member $SAMAccountName}
 		$userGroups = $null
 }
$users | ForEach-Object {RemoveMemberships $_.SAMAccountName}

When I run this, I receive the following error:

Get-ADGroup : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null argument and tr
y the command again.
At C:\temp\Remove_User4.ps1:19 char:45
+          $userGroups | ForEach-Object {get-adgroup <<<<  $_ | Remove-ADGroupMember -confirm:$false -member $SAMAccoun
tName}
    + CategoryInfo          : InvalidData: (:) [Get-ADGroup], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADGrou
   p

Any assistance would be greatly appreciated.

Regards,
Brian

AD Deleted Objects

$
0
0
Does anyone know of a good script for reporting on Active Directory deleted objects?  I would like to query for them and export the data to an easy to read Excel/CSV file to view details about there deleted stats, like: when they were deleted, samAccountName, CN and other helpful details.

Bulk update manager name for all users in AD from excel or csv

$
0
0
How to  use a csv or excel file  import to bulk modify all users'  "Manager" attribute in AD.  The manager(s) may be or may not be same for the users listed  in the excel sheet. The manager name are available in ad. Suggest some powershell script.

File copy over network using a specific NIC

$
0
0

I have a backup server with six NICs all configured on the same subnet. For various reasons we do not want to use NIC teaming. Also we cannot move to 10Gbps switching.
It has several fast disk arrays and two tape devices so storage will not be a bottleneck.
I want to run several copy scripts across the network at the same time throughout the night. To increase throughput I would like to have the different copy scripts all use different physical NICS. If they all use the same NIC maximum throughput will be limited to 1Gbps.
Is there any way to set command or the script environment to use a specific NIC?

<o:p></o:p>


powershell website access

$
0
0

When one does something like

$ie = new-object -com internetexplorer.application

$ie.navigate("192.168.10.1")

Internet explorer opens along with an additional window asking for login information.  How do I access the additional window from powershell?

I've tried different methods but can not find the login window.

$ie.document

$ie.document.doeumentelement

$ie.document.childnodes

any help would be appreciated.

RAC

Exchange 2007 - Powershell commands - help needed to create a batch file

$
0
0

Environment : Exchange 2007 (ISA, EDGE, CAS+HUB (both on one server) and Mailbox in CCR  - SP3 RU5

Got a list of powershell commands, wants to create a batch script (if not a powershell script) to run all commands in one go using the task scheduler and needs output either in text or html file, pls help.

Get-MailboxDatabase –Server <Exchange server name> –Status | ft Name, Mounted

Test-ServiceHealth –Server <Exchange server name>

Get-StorageGroupCopyStatus –Server <Exchange server name>

Get-MailboxDatabase –Server <Exchange server name> –Status | ft Name, lastfullbackup, lastincrementalbackup

Test-MapiConnectivity –Server <Exchange server name>

Get-ClusteredMailboxServerStatus –identity:<Exchange server name>

Thanks


Inderjit

i am looking for the most efficient way (fastest) of adding a single user to many groups at once

$
0
0

I know there are several ways to do everything in PS but now i need the most efficient one.

The situation:

I have thousands of users and their group memberships change frequently, I get an input file that I do not controll as a line such that first item is the user followed by a varying number of groups, like:

dans,grpA,grpB,grpC

ruthd,grpG,grpB,grpQ,grpZ

each input file can have thousands of lines and i do need the script to be optimized - ie run as fast as possible

much obliged

Roy


roys99

Disable Internet Detection on Adapters

$
0
0

We don't want certain servers on our network to have have access to the internet. They are placed on private subnets with no routing to the internet. All of the interfaces for these servers show a yellow triangle because the servers cannot talk to the internet. Is there any way to stop these servers from trying to go to the internet, and can we set the interface so that it doesn't detect that no internet is available? All servers are Windows Server Enterprise or Standard 2008 R2 SP1.

Need Powershell Script to get shared folder and NTFS permission from list of servers

$
0
0

Hi Friends,

 

I need powershell script to dump all the shared folder and thier permission from serverlist.txt. the below code just giving me the shares but not the permissions.

$strComputer = gc C:\ps-test\serverlist.txt
foreach ($computer in $strComputer) {
$colItems = get-wmiobject -class "Win32_Share" -namespace "root\CIMV2" -computername $computer
foreach ($colItem in $colItems) {
$sharename = $colItem.Name
$share = "\\" + $computer + "\" + $sharename | Out-File C:\ps-test\result.txt -NoClobber -Append
$share
}
}

Powershell Script Query

$
0
0

Apologies for being vague in the title.

We have a Powershell script that interrogates a text files containing a list of servers to report on available disk space.

The script works and reports as expected, flagging those servers were we're unable to report on due to OS not suitable, not contactable etc. with an error message. So even if the server name entered into the text file is incorrect, it would\should show in the report.

My query is that for some reason some of the server entries in the text file are being 'skipped over'.

I have tried running with a test text file containing just two of the Host names and again with just IP addresses of one that does report and one that is skipped.  I am getting the same results i.e. just one server being reported. There are no discernible differences between the two servers i.e. Vlans, OS, permissions etc.


Redgie


is it possible to remove a "line" from a jagged array WITHOUT rewriting entire array or creatinga 2nd one?

$
0
0

also, it is very nice to read a csv file and provide header names so in script i can refer to items in the array bu name.

BUT how do i create a NEW array in the script with header names?


roys99

Creating an Object from a text file

$
0
0
Hi guys!
I've just started learning Powershell and I'm really newbie at it! so sorry for that


but i have a big problem! this is my scenario:

I've created a text file that contains some first names and last names that has been separated by space like this:
Jack   Nicholson
Tom    Cruise
.
.
I want to create an object with this in order to  add multiple users in A.D
I used these commands:
$array = get-content name.txt | foreach (
>>$name = @{}
>>$name.first , $name.last = $_.Split()
>>$name
>> )
 
But i received this error:
Missing closing ')' in expression.
At line:3 char:1
+  <<<< $name.first , $name.last = $_.Split()
    + CategoryInfo          : ParserError: (CloseParenToken:TokenId) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndParenthesisInExpression


can you help me please? what's the problem ? what should i do?


Powershell script for database values of users

$
0
0
Hi

I have a list of 100 Exchange 2010 mailboxes in a file named d:\users.txt

Management have asked me to find the following info per mailbox and place in a CSV file with seperate columns (so data can be filtered etc in Excel):


1. Database name

2. For the Database, the RPCClientAccessArray attribute value

3. For the Database, the list of Servers and their Preference

4. The Username

For anyone that is not clear on Exchange Powershell, if it was one mailbox I would get the info as following:

Get-Mailbox -Identity ME

From here, I would use the Database: value (e.g. DB01)

Then:

Get-MailboxDatabase -Identity DB01

And use the RPCCLientAccessArry and Preference values

Can't Create New-ADUser with -CN and -Name Parameters!

$
0
0

Hello,

I'm trying to create a new AD user with the New-ADUser command. It created an AD user but the name is different. i.e., in AD, it shows as "Test Admin" when I manually create the user. When I create with command, it created the user like this: "Test.Admin"

Upon closer look:

SamAccountName: Test.Admin
CN: Test.Admin
Name: Test.Admin

PS C:\Windows\system32> Get-ADUser -Identity "Test.Admin" -Properties * | FL CN, Name

CN   : Test.Admin
Name : Test.Admin

I tried to specify both CN and Name parameters, but it seems to be they didn't exist! Can anyone let me know how can I specify both CN and Name parameters while created a new AD account with New-ADUser command?

Any further help would be appreciated. Thank you!

Create a new scheduled task at logon

$
0
0
I need to run/create a scheduled task in Powershell without doing any additional modules besides what comes standard. My Task needs to run when the user logs back in and I need to run a script. I am still very new to Powershell and am having problems digging through the responses that others have given/gotten for their issue. To make this a little more simple the script I need to run is in a remote location \\example\script.ps1. Then after the task runs I need to delete the scheduled task. Can someone please help me?
Viewing all 2562 articles
Browse latest View live


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