community.windows.win_user_profile (2.2.0) — module

Manages the Windows user profiles.

Authors: Jordan Borean (@jborean93)

Install collection

Install with ansible-galaxy collection install community.windows:==2.2.0


Add to requirements.yml

  collections:
    - name: community.windows
      version: 2.2.0

Description

Used to create or remove user profiles on a Windows host.

This can be used to create a profile before a user logs on or delete a profile when removing a user account.

A profile can be created for both a local or domain account.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a profile for an account
  community.windows.win_user_profile:
    username: ansible-account
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a profile for an account at C:\Users\ansible
  community.windows.win_user_profile:
    username: ansible-account
    name: ansible
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove a profile for a still valid account
  community.windows.win_user_profile:
    username: ansible-account
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove a profile for a deleted account
  community.windows.win_user_profile:
    name: ansible
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove a profile for a deleted account based on the SID
  community.windows.win_user_profile:
    username: S-1-5-21-3233007181-2234767541-1895602582-1305
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove multiple profiles that exist at the basename path
  community.windows.win_user_profile:
    name: ansible
    state: absent
    remove_multiple: yes

Inputs

    
name:
    description:
    - Specifies the base name for the profile path.
    - When I(state) is C(present) this is used to create the profile for I(username) at
      a specific path within the profile directory.
    - This cannot be used to specify a path outside of the profile directory but rather
      it specifies a folder(s) within this directory.
    - If a profile for another user already exists at the same path, then a 3 digit incremental
      number is appended by Windows automatically.
    - When I(state) is C(absent) and I(username) is not set, then the module will remove
      all profiles that point to the profile path derived by this value.
    - This is useful if the account no longer exists but the profile still remains.
    type: str

state:
    choices:
    - absent
    - present
    default: present
    description:
    - Will ensure the profile exists when set to C(present).
    - When creating a profile the I(username) option must be set to a valid account.
    - Will remove the profile(s) when set to C(absent).
    - When removing a profile either I(username) must be set to a valid account, or I(name)
      is set to the profile's base name.
    type: str

username:
    description:
    - The account name of security identifier (SID) for the profile.
    - This must be set when I(state) is C(present) and must be a valid account or the
      SID of a valid account.
    - When I(state) is C(absent) then this must still be a valid account number but the
      SID can be a deleted user's SID.
    type: sid

remove_multiple:
    default: false
    description:
    - When I(state) is C(absent) and the value for I(name) matches multiple profiles the
      module will fail.
    - Set this value to C(yes) to force the module to delete all the profiles found.
    type: bool

Outputs

path:
  description: The full path to the profile for the account. This will be null if
    C(state=absent) and no profile was deleted.
  returned: always
  sample: C:\Users\ansible
  type: str

See also